0

I deleted all tables in database, but my error is :

table.questions exists

so I can not migrate them, does it depend on something else as well?

parastoo
  • 2,211
  • 2
  • 21
  • 38

5 Answers5

7

You can run:

php artisan migrate:refresh

to rollback all the tables (including the migrations table) and recreate everything again.

Sapnesh Naik
  • 11,011
  • 7
  • 63
  • 98
3

It's impossible if you really removed all the tables from database.

Make sure you really deleted all tables including migrations table.

Normally when you want to revert all migrations you should run:

php artisan migrate:reset

If you haven't done this assuming you have are running Laravel 5.5 you can run:

php artisan migrate:fresh

I would advise you to read the whole Migrations documentation to know how they work and how you should create them. In fact you should not remove tables manually and just run:

php artisan migrate:rollback

to rollback migrations previously run or as I already said you can run one one previously mentioned commands to rollback or rollback and run again your migrations.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
  • 1
    @amini.swallow Are you sure your application is using database you think it's using? Run `php artisan migrate:status` to see what migrations were run, also take a look at `.env` to see database name and run `php artisan config:clear` to make sure no old database connection is cached. – Marcin Nabiałek Dec 27 '17 at 12:23
  • Yeah , I am sure – parastoo Dec 27 '17 at 12:44
  • So if you really have clean database it's impossible that you are getting the error. The only chance is when in 2 or more migrations you try to create the same table. Verify if you don't have `Schema::create('questions'` in more than one migration – Marcin Nabiałek Dec 27 '17 at 12:45
  • I found it,It was because of middleware – parastoo Dec 27 '17 at 13:02
2

You get this error because you already have this table in DB. You need to drop a table in down() method of each migration and use php artisan migrate:rollback command to delete last batch of executed migrations.

In 5.5 you also can use php artisan migrate:fresh if you do not drop tables in the down() method.

https://laravel.com/docs/5.5/migrations#rolling-back-migrations

Or you can just manually recreate a DB and run php artisan migrate command.

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
1

I found it , I had a middleware in boot for question table and added this:

   if(\Schema::hasTable('questions')) {
       ....
     }
parastoo
  • 2,211
  • 2
  • 21
  • 38
0

I've made comments table before and I was making another one for addresses and it said you can't create comments table again!! I delete comments table and migrate again, both tables made successfully.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 04 '23 at 17:16