0

I have a table with a primary key. I want to add a new column and make that one the primary key. However, I can't drop the primary key constraint on the old column, because it is referenced as a foreign key in another table. So I dropped the foreign key constraint and the index:

ALTER TABLE experiments DROP FOREIGN KEY experiments_ibfk_1
ALTER TABLE experiments DROP INDEX `analysisfk`;

I checked with show create that both constraint and index are gone. Then I tried to drop the primary key again with

ALTER TABLE analysis DROP PRIMARY KEY;

However, I still got an Error 1025. Am I overlooking something?

SOLVED: There was another key constraint which I overlooked because of a misleading name. Leaving this here anyway as it shows some useful stuff

Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
LizzAlice
  • 678
  • 7
  • 18
  • does this help? https://stackoverflow.com/questions/160233/what-does-mysql-error-1025-hy000-error-on-rename-of-foo-errorno-150-me –  Jun 19 '19 at 14:52
  • @tuckbloor not really, I used `drop foreign key` as well, I didn't drop the column but that's because I want to keep it – LizzAlice Jun 19 '19 at 14:54
  • Just tried it myself and works as expected the PK is gone. Now you can create a new one. – The Impaler Jun 19 '19 at 15:07
  • @TheImpaler yeah but that is exactly the problem, if I try dropping the primary key with the above command, I get an error – LizzAlice Jun 19 '19 at 15:09
  • Show us the DDL for all tables involve. So we can tell you wich order you need to drop Keys and Index. – Juan Carlos Oropeza Jun 19 '19 at 15:20

0 Answers0