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';0
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.
Random Code Snippet Queries: Laravel
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- How to upload image in laravel 8
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- Laravel hasmany select not working
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- Session Doesn't Work on Redirect
- How to create project_user pivot table in laravel
- Target class [admin] does not exist.
- Php artisan make model, factory, migration and controller in single command
- Store logged in user details in session and display in view in laravel
- Wheredate in laravel not working
- How to restore multiple records after soft-deletes in Laravel
- How to check email is valid or not in Laravel
- Laravel 9 route group with controller
- How to add dynamic page title in Laravel view
- How to display order by null last in laravel
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- Return redirect laravel not working
- Redirect from www to non www in laravel using htaccess
- How to add a key value pair to existing array in laravel
- Get latest record by created at in Laravel
- Create record with unique slug in laravel
- Laravel create default admin user
- Permission denied error while creating storage link in Laravel
- How to display HTML tags In Laravel blade