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 (
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
- Shorter syntax for whereHas with call back function in laravel
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- Create record with unique slug in laravel
- How to get last month records in Laravel
- Get latest record by created at in Laravel
- How to prevent host header attack in Laravel
- Create project table with model and migration
- Attempt to read property "avatar" on null in Laravel
- Call to a member function update() on null
- Extra Filter Query on Relationships in Laravel
- Get ids in array from users table
- Rename Pivot Table in Laravel
- Rendering HTML from database table to view in Laravel
- Redirect to another view from controller in laravel
- Use withCount() to Calculate Child Relationship Records
- Laravel file size validation not working
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- How to fetch single row data from database in laravel
- How to get IP address in laravel
- How to generate .env file for laravel?
- How to add foreign key in laravel using migration
- Laravel 9 pagination with search filter
- Display first n record from collection in laravel view
- How to upload image in laravel 8
- Multiple Level eager loading in Laravel