
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.
Answers 1
-
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');
0Laravel 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.
Random Code Snippet Queries: Laravel
- How to fill a column automatically while creating records in Laravel
- Global scope in Laravel with example
- The use statement with non-compound name 'Auth' has no effect
- Get 30 days older records from table in laravel
- How to get id of next record in laravel
- How to set column as primary key in Laravel model
- How to check query string exists or not in laravel blade
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- Add a subselect based on relationship using withAggregate method
- Laravel route parameter
- FirstOrCreate() Not Inserting Model
- Wheredate in laravel not working
- Class 'App\Rules\Hash' not found in Laravel
- Array to string conversion laravel Controller
- How to pass link from controller to view in laravel on ajax call
- How to add dynamic page title in Laravel view
- The openssl extension is required for SSL/TLS protection but is not available
- How to get selected categories on edit record with Select2
- How to add script on specific view file in laravel while extending layout
- How to add unique records in pivot columns of Laravel pivot table
- How to return error message from controller to view in laravel
- Get laravel version
- Target class [admin] does not exist.
- Laravel URL validation not working
- Update if exist else insert new record in laravel