Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lifesound's avatar

Migration refresh and rollback order

when migrate my migration ..

I'm very confused and has errors when put relations .

i had these two errors , i tried to reorder my migration , but still have different table names errors ..

  [Illuminate\Database\QueryException]
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'role_user' already exist
  s (SQL: create table `role_user` (`role_id` int unsigned not null, `user_id` int unsigne
  d not null) default character set utf8 collate utf8_unicode_ci)



  [PDOException]
  SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'role_user' already exist
  s

how to order my tables ..

This is my order

migration   batch
2011_08_11_013917_create_material_order_table   1
2014_10_12_000000_create_users_table    1
2014_10_12_100000_create_password_resets_table  1
2016_03_21_010421_create_orders_table   1
2016_03_21_010549_create_types_table    1
2016_03_21_010722_create_materials_table    1
2016_03_21_010814_create_ratings_table  1
2016_03_21_010839_create_workers_table  1
2016_03_21_011205_create_costs_table    1
2016_03_21_012114_create_locations_table    1
2016_06_02_181122_create_assignments_table  1
2016_06_25_001455_create_bills_table    1
2016_07_26_195012_create_roles_table    1
2016_08_06_205440_create_permissions_table  1
2016_08_11_012100_create_order_worker_table 1

thanx alot

0 likes
5 replies
ctroms's avatar
ctroms
Best Answer
Level 15

I don't see the migration for the role_user table. Is that table being created in one of your other migrations?

If it is, make sure you have a line to drop that table in your down method. Schema::drop('role_user');

When you run php artisan migrate:refresh do you see that all of the tables are "Rolled back" before they are migrated again?

1 like
lifesound's avatar

thx @ctroms

i have line for drop (role_user) Schema::drop('role_user');

when migrate:refresh i had these errors

SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent r
ow: a foreign key constraint fails (SQL: drop table `roles`)
  [PDOException]
  SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent r
  ow: a foreign key constraint fails````
ctroms's avatar

Can you post your foreign key definitions for your roles table and your permissions table. There is likely still a foreign key relationship that exists at the time the roles table is being dropped. Perhaps on your permissions table.

lifesound's avatar

After some arrangements for migrations

it works

Please or to participate in this conversation.