3

Some how, my database has gotten into a bad state. I previously had a table named live_stream. When I tried to drop a foreign key constraint, I got an error that mariadb could not rename #sql-26_e7a to live_stream. Now when I try to run the following statement, I get this error.

Can't create table live_stream (errno: 150 "Foreign key constraint is incorrectly formed")

CREATE TABLE live_stream (idbigint(20) NOT NULL PRIMARY KEY);

As you can see I don't have any foreign key constraints in the definition. If I try the exact same definition with a different table name, it works. If I try to drop the table, mariadb complains that live_stream doesn't exist. Its like the table or foreign key are stuck in a transaction or something like that.

I am using galara with maria db 10.3.

UPDATE

I believe the problem was introduced when a foreign key and unique index were given the same name. I recreated the scenario, and when I try to drop the index, mariadb prevents it.

* UPDATE 2 * Here is the output of SHOW ENGINE INNODB STATUS; enter image description here

* UPDATE3 *

Here are the steps to reproduce.

create table tb1 ( id bigint null, constraint tb1_pk primary key (id) );

create table tb2 ( id bigint null, tb1_id bigint null, constraint tb2_pk primary key (id), constraint tb2_tb1_id_fk foreign key (tb1_id) references tb1 (id) );

ALTER TABLE tb2 ADD CONSTRAINT tb2_tb1_id_fk UNIQUE (tb1_id, tb1_id);

drop index tb2_tb1_id_fk on tb2;

The problem is that the unique constraint has the same name as the foreign key and references the same column twice.

tanner burton
  • 1,049
  • 13
  • 14

0 Answers0