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 display order by null last in laravel
- SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel8.projects' doesn't exist
- Get last record from table in laravel
- Trying to get property 'title' of non-object
- How to display validation error in laravel
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- How to generate .env file for laravel?
- How to automatically update the timestamp of parent model in Laravel
- On delete set foreign id column value null using migration in laravel 8
- Delete all related comments on deleting a post in Laravel
- How to fetch single row data from database in laravel
- Post model with title and body in laravel 8
- How to get random string in Laravel
- Send post data from controller to view
- Import/Use Storage facade in laravel
- How to get data from two tables in laravel
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- How to get file extension from input type file in laravel
- Update email with unique validation in laravel
- How to disable timestamps in laravel
- How to check duplicate entry in laravel
- Permanently delete a record in laravel
- How to avoid duplicate entries in pivot table in Laravel
- Attempt to read property "avatar" on null in Laravel
- Create records using relationship in laravel