
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 create belongstomany relation using custom name on custom pivot table
- How to check record exist or not in relationship table
- 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 display a specific word from a string in laravel
- Laravel create table migration with model
- Redirect from www to non www in laravel using htaccess
- Show old value while editing the form in Laravel
- Laravel get all records with pagination
- Get laravel version
- Ignore Records where a field has NULL value in Laravel
- Input file with max size validation in laravel
- Save or update pivot table data with additional column in Laravel
- If condition in Laravel 9
- How to check column value of a record is null or not in laravel
- How to upload image in laravel 8
- Create records using relationship in laravel
- Insert current date time in a column using Laravel
- Update last created record in Laravel
- Call to a member function pluck() on array
- How to get records in random order in laravel
- Laravel migration add foreign key to existing table
- Cast Array to an Object in Controller and then pass to view in laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- How to get route method name in Laravel
- Create project table with model and migration