0

enter image description hereI previously created users table. Now I have created a new migration to create a new books table inside my schema. When I try to run the command

php artisan migrate it shows me:

[Illuminate\Database\QueryException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' alre ady exists (SQL: create table users (id int unsigned not null auto_incr ement primary key, username varchar(255) not null, email varchar(255) n ot null, password varchar(255) not null, created_at timestamp default 0 not null, updated_at timestamp default 0 not null) default character set utf8 collate utf8_unicode_ci)

My question is just the same as 2 and codes i ran are same as well. So, i have tried all the solutions suggested here.But they don't work for me.As i can't make comments on the post i have to post it as a new question.Hope you will realise my concern and help me out.

3 Answers3

3

Thank you for the result!

In that case, you may delete all table, and redo php artisan migrate.

If you would not feel like doing it, you can insert a record of migration file name which was created already to your migrations table as well and then run php artisan migrate.

In that case, you don't need to delete tables.

For example, you seem to created users table, so please insert record whose migration is 2014_10_12_000000_create_users_table like following.

enter image description here

then, when you run php artisan migrate:status, you will get the result as follows.

enter image description here

if this is the case, if you run php artisan migrate, migration file later 2014_10_12_200000_create_password_resets_table will be execute.

In this way, you should insert the record of migration file name which is created already, and then run php artisan migrate, it will work well!

P.S.

As @mschuett says in Laravel Migration table already exists but i want to add new not the older, your migrations table is messed up.

Because, you have users table in your database, but migration of 2014_10_12_00000_create_users_table isn't executed.

If there are multiple migration files, if you run it and it fails somewhere, the migration status have been Y to where you ran.

Yujiro
  • 351
  • 1
  • 6
  • I've deleted all the database from mysql and then when i ran php artisan migrate it only shows user and reset password tables. The other tables which i created manually they are not in mysql database. – Farhan Mahmud Hemel Aug 13 '17 at 17:08
3

As your screenshot shows, none of your migrations have actually run. You must have created the users table manually, or maybe you did run a migration but it somehow got messed up.

If you don't mind losing whatever data is in the tables, the simplest fix is (you will lose all data in your tables!):

php artisan migrate:refresh

which will rollback all migrations, and run them fresh again.

More info in the docs.

Don't Panic
  • 13,965
  • 5
  • 32
  • 51
1

php artisan migrate:refresh will delete all data and recreates tables, while migrate just creates tables what doesn't exist yet.

In case to refresh only some tables, (if migrate doesn't work so), helped me to delete those tables and table rows in migrations table and further successfully do php artisan migrate. (yet tried only on 4.2, but it may work on upper versions too)

Nerius Jok
  • 3,059
  • 6
  • 21
  • 27