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
- How to start websocket server in laravel
- How to get database name in Laravel 9 ?
- Pass variable from blade to controller Laravel
- Call to a member function pluck() on array
- File_put_contents(/var/www/html/w3code/storage/framework/sessions/CXwN3EXKxERD6jgy3rADcaAAbAx8FRKih2JK7UO9): Failed to open stream: Permission denied
- Send OTP using textlocal api in laravel
- Define variable and use in Laravel controller method
- Pagination in laravel
- How to use bootstrap pagination in laravel 8
- Get ids in array from users table
- Get posts belongs to a specific user in Laravel
- 419 page expired error in Laravel
- How to add a key value pair to existing array in laravel
- How to insert dynamic values to additional column with pivot column in pivot table on multiple records
- The use statement with non-compound name 'Auth' has no effect
- How to display 1 day ago in comments in laravel view
- Always load the relationship data with eager loading in Laravel
- How to add script on specific view file in laravel while extending layout
- Laravel insert query not working
- Method Illuminate\Http\Request::validated does not exist
- Print last executed query in laravel
- Route group with URI prefix using middleware and route name prefixes
- How to restore deleted records in laravel
- How to add unique records in pivot columns of Laravel pivot table
- How to get specific columns using Laravel eloquent methods