4

I am upgrading my quartz.net version from 1.0.3 to 2.0.2 There is a migration script for database schema, which was was written for MSSQL, and I am trying to write a MYSQL version of it.

However, I haven't been able to drop primary keys (which I need to).

Original MSSQL version of script:

ALTER TABLE BLOB_TRIGGERS DROP CONSTRAINT BLOB_TRIGGERS_PKEY;
ALTER TABLE BLOB_TRIGGERS DROP CONSTRAINT BLOB_TRIGGERS_TRIGGER_NAME_FKEY;
ALTER TABLE SIMPLE_TRIGGERS DROP CONSTRAINT PK_SIMPLE_TRIGGERS;
ALTER TABLE SIMPLE_TRIGGERS DROP CONSTRAINT FK_SIMPLE_TRIGGERS_TRIGGERS;
ALTER TABLE CRON_TRIGGERS DROP CONSTRAINT PK_CRON_TRIGGERS;
ALTER TABLE CRON_TRIGGERS DROP CONSTRAINT FK_CRON_TRIGGERS_TRIGGERS;
ALTER TABLE TRIGGERS DROP CONSTRAINT PK_TRIGGERS;
ALTER TABLE TRIGGERS DROP CONSTRAINT FK_TRIGGERS_JOB_DETAILS;
ALTER TABLE JOB_DETAILS DROP CONSTRAINT PK_JOB_DETAILS;

For simplicity, I am trying the first statement there

ALTER TABLE BLOB_TRIGGERS DROP CONSTRAINT BLOB_TRIGGERS_PKEY;

Here are what I have tried and results:

  • ALTER TABLE BLOB_TRIGGERS DROP PRIMARY KEY;

[Err] 1025 - Error on rename of '.\quartz_local#sql-df8_9' to '.\quartz_local\BLOB_TRIGGERS' (errno: 150)

  • ALTER TABLE BLOB_TRIGGERS DROP INDEX 'PRIMARY';

[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''PRIMARY'' at line 1

  • ALTER TABLE BLOB_TRIGGERS DROP INDEX PRIMARY;

[Err] 1025 - Error on rename of '.\quartz_local#sql-df8_9' to '.\quartz_local\BLOB_TRIGGERS' (errno: 150)

  • ALTER TABLE BLOB_TRIGGERS DROP PRIMARY KEY;

[Err] 1025 - Error on rename of '.\quartz_local#sql-df8_9' to '.\quartz_local\BLOB_TRIGGERS' (errno: 150)

My Mysql version is 5.5.16

EDIT: To check the indexes: MYSQL Show index results

EDIT2: Foreign keys on request: Create table sql

SadullahCeran
  • 2,425
  • 4
  • 20
  • 34

4 Answers4

4

(errno: 150) is the giveaway: This means Foreign key definition problem. I suspect some other table has a foreign key constraint depending this PK, so you need to drop that first and rebuild it later.

Edit: With the images you posted, this becomes clearer:

The FK from BLOBS_TRIGGERS to TRIGGERS is made up from the PK. So if you drop the PK, the contraint becomes stale. You need to drop and later recreate the constraint.

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92
1

After brief Googling, I'm pretty sure the error message is a little misleading. There seem to be a lot of ALTER TABLE statements that might result in that error message.

I'd check to see if there are foreign key references to this table.

Mike Sherrill 'Cat Recall'
  • 91,602
  • 17
  • 122
  • 185
  • How can I check foreign key references pointing to this table (BLOB_TRIGGERS) ? – SadullahCeran Feb 11 '12 at 19:14
  • I think you need to [query the KEY_COLUMN_USAGE table](http://dev.mysql.com/doc/refman/5.5/en/key-column-usage-table.html) in information schema views. – Mike Sherrill 'Cat Recall' Feb 11 '12 at 19:17
  • I did and confirmed there is no foreign key pointing to BLOB_TRIGGERS. – SadullahCeran Feb 11 '12 at 19:20
  • However, if I first remove the foreign key pointing from BLOB_TRIGGERS to other tables, then I can remove primary key. Problem is solved, but I don't really get the reason behind. – SadullahCeran Feb 11 '12 at 19:21
  • It's not unusual for any SQL dbms to complain when you try to drop something that's involved in a dependency. MySQL just seems to have a suboptimal error message for it. When you try to drop a primary key constraint that's referenced by a foreign key in PostgreSQL, you get an error message that basically says a foreign key depends on the constraint you tried to drop, so use DROP . . . CASCADE to drop dependent objects. – Mike Sherrill 'Cat Recall' Feb 11 '12 at 19:27
0

I had the same problem. Deleting foreign keys in the table did not help. There were no other tables referencing the one that had the primary key I was trying to drop. I finally solved the problem by using mysqldump to export the table to an ASCII file. I then edited the file to change the primary key to one I wanted, then I reimported using the mysql command line interface.

0

ALTER TABLE tablename DROP PRIMARY KEY;

Sanjeev Kumar
  • 193
  • 1
  • 7