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 pass data to multiple partial view files in laravel
- Illuminate\Database\QueryException could not find driver
- Add a subselect based on relationship using withAggregate method
- Composer create project laravel/laravel example app
- How to automatically update the timestamp of parent model in Laravel
- Send post data from controller to view
- How to return error message from controller to view in laravel
- How to validate website url in laravel using validaiton
- Send OTP using textlocal api in laravel
- Symlink(): No such file or directory
- How to upload image in laravel 8
- Get current URL on visit URL in Laravel
- Redirect to previous page or url in laravel
- How to get data from two tables in laravel
- PhpMyAdmin - Error The mysqli extension is missing
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- How to display validation error in laravel
- Wheredate in laravel not working
- How to remove P tag from CkEditor in Laravel?
- How to get column names from table in Laravel
- How to get laravel errors folder in views directory in laravel
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- Laravel append URI in route
- Session Doesn't Work on Redirect
- How to pass query string with pagination in laravel