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
- Get Array of IDs from Eloquent Collection
- Create a record if not exist in laravel
- How to get specific columns using with method in laravel Eloquent relationship
- How to customize or Change validation error messages
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- Rendering HTML from database table to view in Laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- Laravel get all records with pagination
- After image selected get validation error in laravel
- Order by multiple columns in Laravel
- How to decrypt laravel password
- How to get IP address in laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- How to pass query string with pagination in laravel
- Call to undefined method App\Models\User::follow()
- Skip first n record and display rest records in laravel view
- How to increment column value of table in Laravel
- How to insert ckeditor data into database in Laravel?
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- Update existing pivot table data in laravel
- How to create controller in laravel
- How to get the id of last record from collection object in laravel view
- Redirect from www to non www in laravel using htaccess
- How to create and run user seeder in laravel