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
- InRandomOrder() method with example in laravel
- External link not working in laravel blade
- How to check column value of a record is null or not in laravel
- How to get random string in Laravel
- How to get session in blade Laravel ?
- Route not defined in Laravel
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- How to disable timestamps in laravel
- Extra Filter Query on Relationships in Laravel
- How to access the nth object from Laravel collection object ?
- Input file with max size validation in laravel
- Convert multidimensional array to single array in Laravel
- Count all and get 10 records after where condition in laravel
- Drop foreign key column in Laravel using migration
- How to Access Array in blade laravel
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- How to change default timestamp fields name in Laravel
- Generate random string lowercase in Laravel
- How to validate website url in laravel using validaiton
- Use withCount() to Calculate Child Relationship Records
- How to create new user without form submission in laravel
- How to call Laravel route in jQuery
- The use statement with non-compound name 'Auth' has no effect
- How to show data by ID in laravel?
- How to use more than one query scope in Laravel