2

I seem to have run across a strange situation where there is a specific table name that I cannot use. Let me explain.

CREATE TABLE IF NOT EXISTS hotstick_work_orders (
    work_order_id BIGINT UNSIGNED NOT NULL,
    step_id TINYINT UNSIGNED NOT NULL,
    user_id INT UNSIGNED NOT NULL,
    FOREIGN KEY (work_order_id) REFERENCES work_orders (id) ON DELETE CASCADE ON UPDATE NO ACTION,
    FOREIGN KEY (step_id) REFERENCES hotstick_steps (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
    FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE NO ACTION ON UPDATE NO ACTION,
    PRIMARY KEY (work_order_id, step_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

This works fine on my local MySql stack (v5.6.17), but gives me error code #1005 when I try it using PhpMyAdmin (v4.0.10.7, MySQL v5.5.42) on GoDaddy.

Okay, you say, this is obviously just another case where the FK definitions don't match perfectly, or possibly one where a referenced table is missing an index on the column. However, I can't even create the table without FKs - the following fails just the same:

CREATE TABLE IF NOT EXISTS hotstick_work_orders (
    work_order_id BIGINT UNSIGNED NOT NULL,
    step_id TINYINT UNSIGNED NOT NULL,
    user_id INT UNSIGNED NOT NULL,
    PRIMARY KEY (work_order_id, step_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Even more interesting, if I run the original create table query but use a different name, even hotstick_work_order (without the final s), it works FINE. I can rename this table to anything I want (including longer names), EXCEPT for hotstick_work_orders. Trying gives me error #1025, but only with that specific name.

E.g.:

 RENAME TABLE hotstick_work_order TO hotstick_work_orders;
 Resulting Error: #1025 - Error on rename of './db/hotstick_work_order' to './db/hotstick_work_orders' (errno: -1)

 # Whereas this works fine:
 RENAME TABLE hotstick_work_order TO hotstick_work_orders_something;

I don't have any previous table with that name, nor could I find any existing constraints in the information_schema.table_constraints table.

Of course I can manage using a different table name, no big deal, but I'm very curious - what could possibly cause such behavior?

Brian
  • 336
  • 1
  • 9
  • 2
    did you check if db files of that name already exist? Maybe you've got leftovers from some other failed operation left behind, and mysql is properly refusing to rename your current db's files, because that'd trash those other files. – Marc B Oct 19 '15 at 18:38
  • This may solve your problem: http://stackoverflow.com/questions/160233/what-does-mysql-error-1025-hy000-error-on-rename-of-foo-errorno-150-me. – Gordon Linoff Oct 19 '15 at 18:40
  • Where would I find those? The 'files' table in information_schema is empty. – Brian Oct 19 '15 at 18:41
  • @GordonLinoff I already saw that, and no, it doesn't help. Please read my question more carefully. – Brian Oct 19 '15 at 18:42
  • Did you try to restart the MySQL service to see if it gets solved? – Marco Aurélio Deleu Oct 19 '15 at 18:47
  • @MarcoAurélioDeleu Unfortunately, I can't (at least I don't think so) due to it being on a shared host, otherwise I would definitely have tried that ;) – Brian Oct 19 '15 at 18:49
  • Try to create it as MyISAM then. – Marco Aurélio Deleu Oct 19 '15 at 18:51
  • Also, the only failed operation to occur (recently) was the initial create table attempt, and I have never used that table name before. – Brian Oct 19 '15 at 18:51
  • @MarcoAurélioDeleu I don't see how using MyISAM would help - I can create the table just fine so long as I don't use that one specific name, and I need to use InnoDB so I can have FK constraints. – Brian Oct 19 '15 at 18:53
  • Did you try to use MyISAM without any constraints and with the exact name you need? – Marco Aurélio Deleu Oct 19 '15 at 18:54
  • @MarcoAurélioDeleu Okay, I think I see where you're going with this - just tried, and it worked, so now I can alter the table storage engine and then add my constraints from there. I'll let you know how it goes, but I'm still curious why InnoDB would fail to create a table with that name, constraints or no. – Brian Oct 19 '15 at 18:57
  • Dont' do that!!! http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html – Marco Aurélio Deleu Oct 19 '15 at 18:57
  • I'm pretty sure that warning only applies to system tables, but it didn't work anyway, giving me the exact same error as on rename. – Brian Oct 19 '15 at 19:00

1 Answers1

1

What you're probably suffering from is a bad case of cached naming. A proper server restart might solve your problem, but as you mentioned, you can't do it due to shared server configuration.

When I asked you to create a MyISAM table with the exact name was so that we could establish that the problem was indeed cached indexes or constraints linked to your table name. Now what I recommend you to do is:

  1. Try and Repair the MyISAM table.
  2. Try to Optimize the table.
  3. Execute a SELECT SQL_NO_CACHE * FROM TABLE to stop MySQL from caching queries.
  4. Drop the Table.
  5. Re-create it as you wish it would be (with constraints and all, InnoDB).
Marco Aurélio Deleu
  • 4,279
  • 4
  • 35
  • 63
  • Thanks for the answer, unfortunately that still didn't work (performed all steps in order). :/ If I'm unable to clear the cache manually on shared hosting, I may just have to live with it - certainly not the end of the world. – Brian Oct 19 '15 at 19:06
  • @Brian If you have a small database, you may also try to recreate it from scratch. – Marco Aurélio Deleu Oct 19 '15 at 19:11
  • Tried again with SQL_NO_CACHE - same result as before. – Brian Oct 19 '15 at 19:11
  • It's not 'big data' big, but it would still be more hassle than it's worth. This certainly does seem like a caching issue, but how that specific name got cached is a mystery to me as I only used it for the first time today, and that operation failed. – Brian Oct 19 '15 at 19:16
  • Unfortunately, aside from ignoring it / using a different table name, I haven't. Since no other ideas were forthcoming, however, I decided to accept your answer as it is likely the cause - I suppose we'll see next time GoDaddy restarts Apache... – Brian Oct 19 '15 at 22:44