
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
- Remove several global scope from query
- How to include header file in laravel
- How to avoid duplicate entries in pivot table in Laravel
- How to pass data to route in laravel?
- How to pass variable from controller to model in Laravel
- How to get all route list
- Delete file from amazon s3 bucket using Laravel
- How to add dynamic page title in Laravel view
- How to get user information using hootlex/laravel-friendships package in laravel
- Trying to get property 'title' of non-object
- Get latest record by created at in Laravel
- Automatically remove records using Prunable trait in Laravel
- Laravel delete all rows older than 30 days
- How to call controller function from view in Laravel
- How to add unique records in pivot columns of Laravel pivot table
- Extra Filter Query on Relationships in Laravel
- Laravel hasmany select not working
- How to get the id of last record from collection object in laravel view
- How to call Laravel route in jQuery
- How to delete record in Laravel with ajax
- Database transactions in laravel
- Laravel upload file with original file name
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- How to get tomorrow and yesterday date in laravel
- Call to undefined relationship [user] on model [App\Models\Post]