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

warpig's avatar
Level 12

SQLSTATE[42P07]: Duplicate table: 7 ERROR: relation "roles" already exists

After working on the project during the week I introduced some new tables, altered some columns but now that I've deployed the changes to github and then deploying those changes on Heroku, after accessing the site online, I get a 500 Server Error.

Went into the bash (heroku run bash) and ran php artisan migrate but I got this message:

In Connection.php line 678:

  SQLSTATE[42P07]: Duplicate table: 7 ERROR:  relation "roles" already exists
   (SQL: create table "roles" ("id" bigserial primary key not null, "name" va
  rchar(255) not null, "label" varchar(255) null, "created_at" timestamp(0) w
  ithout time zone null, "updated_at" timestamp(0) without time zone null))


In Connection.php line 471:

  SQLSTATE[42P07]: Duplicate table: 7 ERROR:  relation "roles" already exists

I rolled back the migrations and ran the migrations again but yet again Im still reading the same message above, how can I make this one go away?

At this point and because the nature of the project is NOT professional or for another person I could run fresh but I want to learn because on development I faced this error and let's say I never got to "fixing" it, all I did was to create another migration file and copied and pasted the code that I had. Thanks!

0 likes
4 replies
tykus's avatar
tykus
Best Answer
Level 104

I did was to create another migration file

So, you probably introduced a second migration which attempts to create a roles table?

warpig's avatar
Level 12

Sorry for the best answer I didn't mean to click that hehe! Uhm yeah probably that's what happened on my local environment, what should I do?

warpig's avatar
Level 12

@tykus should I remove the migration file "manually" from the bash and then deploy again ?

tykus's avatar

Yes, Or, whatever you need to do to remove whatever migration is attempting to create the roles table for a second time.

Please or to participate in this conversation.