SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
The error SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id' occurs when you run the migration command using php artisan migrate if the column user_id (which is a foreign key) already exists in your table structure.
-
Check column exists or not in a table using SQL
//SQL Syntax SHOW COLUMNS FROM `table` LIKE 'fieldname'; //SQL Query SHOW COLUMNS FROM `posts` LIKE 'user_id';
You can check if a column exists or not in MySQL using SQL query SHOW COLUMNS FROM `posts` LIKE 'user_id';
This query will return the column name with the data type after executing the SQL query.
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
- Send post data from controller to view
- Create user in Laravel using tinker
- The POST method is not supported for this route. Supported methods: PUT.
- Pass value from controller to model in laravel
- How to validate website url in laravel using validaiton
- How to get date from created_at field in laravel
- How to fill a column automatically while creating records in Laravel
- Extra Filter Query on Relationships in Laravel
- How to check records exist in loaded relationship in Laravel blade view
- Shorter syntax for whereHas with call back function in laravel
- 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`))
- How to pass data to partial view file in laravel
- Create project table with model and migration
- Laravel csrf token mismatch for ajax POST Request
- Call to a member function pluck() on null
- How to remove P tag from CkEditor in Laravel?
- Extract only time from datetime in laravel
- How to create controller in laravel
- Validation errors for multiple forms on same page Laravel
- On delete set foreign id column value null using migration in laravel 8
- Split an Eloquent Collection by half in Laravel
- How to make Copy or Duplicate table row in laravel
- How to check relationship is loaded or not in Laravel
- Page loader in laravel
- Laravel pagination links with query string