
Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table `users` add constraint `users_role_id_foreign` foreign key (`role_id`) references `roles` (`id`))
Syntax error or access violation: 1072 Key column 'role_id' doesn't exist in table (SQL: alter table users
add constraint users_role_id_foreign
foreign key (role_id
) references roles
(id
)) error occurs when you try to migrate a file with a foreign key with $table->foreign('role_id') in laravel 8.
-
Create foreign key role_id in table using migration in laravel 8
//$table->foreign('role_id')->references('id')->on('roles'); //Replace with below code $table->foreignId('role_id')->references('id')->on('roles');
Laravel code while creating foreign id to table using migration in laravel 8. You have to use
$table->foreignId('role_id')->references('id')->on('roles');
in place of$table->foreign('role_id')->references('id')->on('roles');
while migration in laravel.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Method chaining in Laravel
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- Conditional validation in laravel
- Permanently delete a record in laravel
- Update existing pivot table data in laravel
- How to validate URL with https using regex in laravel
- How to display order by null last in laravel
- How to return error message from controller to view in laravel
- How to create pivot table in laravel using migration
- SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist
- Laravel get count with where condition
- How to get random string in Laravel
- How to check data inserted or deleted in pivot after toggle method
- How to get the id of last record from collection object in laravel view
- Credit card validation in laravel
- How to change default timestamp fields name in Laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Laravel 11 project setup on localhost using breeze with blade step by step
- Laravel specific table Migration
- Best Practices for Error Handling in Production Server Code (example code)
- Laravel pagination links with query string
- Update email with unique validation in laravel
- How to create new user without form submission in laravel
- How to display pivot table column value in laravel
- How to add dynamic page title in Laravel view