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.
Random Code Snippet Queries: Laravel
- How to get file extension from input type file in laravel
- Multiple Level eager loading in Laravel
- Symlink(): No such file or directory
- How to pass data to route in laravel?
- How to check find method executed successfully in laravel
- Recursive function example code PHP Laravel
- How to add dynamic page title in Laravel view
- How to insert multiple rows in mysql using loop in laravel?
- Target class [HomeController] does not exist
- How to create new user without form submission in laravel
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- How to get IP address in laravel
- Use withCount() to get total number of records with relationship
- Laravel create multiple records in Pivot table
- How to customize or Change validation error messages
- The openssl extension is required for SSL/TLS protection but is not available
- How to get random string in Laravel
- Redirect from www to non www in laravel using htaccess
- Create project table with model and migration
- How to check record exist or not in relationship table
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- Class "App\Http\Controllers\Auth\Verified" not found
- Attempt to read property "avatar" on null in Laravel
- How to create belongstomany relation using custom name on custom pivot table
- How to pass link from controller to view in laravel on ajax call