I've created an Auth project with laravel 5.5 and created new migration and when I migrate I receive this error msg:
In Connection.php line 647:
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists
(SQL: create table `users` (
`id` int unsigned not null auto_increment primary key,
`name` varchar(255) not null,
`username` varchar(255) not null,
`email` varchar(255) not null,
`password` varchar(255) not null,
`remember_token` varchar(100) null,
`created_at` timestamp null,
`updated_at` timestamp null,
`role` int not null
) default character set utf8mb4 collate utf8mb4_unicode_ci
)
In Connection.php line 449:
SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists
i try php artisan migrate --force and php artisan migrate:rollback
and try to drop all tabels and migrate it again and still ahve this error
It sounds like you're using a database that already has a
users
table, but nomigration
table. Therefore, when you run the migration, it's attempting to create theusers
table again.There are two things you can try:
1) Try setting up a new (empty) database in MySQL and update the settings in your
.env
file to point to this new DB. Runphp artisan migrate
and see if your migrations are correctly applied.2) Using your existing database, delete / drop all tables (make a backup of the data if you want to retain it), and then run
php artisan migrate
and see if that fixes the issue.to understand the problem and find a solution you need to understand how migration works. migrations work on a creation date basis way. whenever a migration is created the current time stamp is append to the file name. and migration runs according to that time stamp. NOW LARAVEL creates two migrations named 2014_10_12_000000_create_users_table.php and 2014_10_12_100000_create_password_resets_table.php. as the rule of laravel whenever you are going to run migration these two files are going to migrate but users table already exists. delete these to files and hope your problem will be solved. one thing, if you are handling databse in laravel using schema and migrations do not ever delete db manually. it will cause you unnecessary problems. the migration table keeps track of all the migrations you run and deleting db manually will break that track of keeping data in migrations table. so next time you run a schema, laravel would not be able to understand whats going on and will create errors. hope that will help you.
after reading error msg in CMD (DOS) and check laravel documentation
error in length i dont know if any one see this error before or not but when i edit length its work
i edit 3 migration as below :-
and now its
number 2 it was
and now its :-
number 3 it was :-
now its :-
Have you created a new migration for the table 'users'?
Laravel by default when a new project is created will produce a migration for a users table. This will mean if you create a new migration with the 'users' table it will try to create the table twice hence causing the error.
You can either remove the laravel created migration, change the name of your new table or modify the laravel migration rather than creating your own.