0

The problem

With no previous migration pending I run:

app/console doctrine:migration:diff
app/console doctrine:migration:migrate

I got this error:

ALTER TABLE session ADD CONSTRAINT FK_9955C22EA76ED395 FOREIGN KEY (user_id) REFERENCES user(id)
Migration 20130320103822 failed during Execution. Error SQLSTATE[HY000]: General error: 1005 Can't create table 'mydb.#sql-3e4_75e0' (errno: 150)

[PDOException]                                                                                    
  SQLSTATE[HY000]: General error: 1005 Can't create table 'mydb.#sql-3e4_75e0' (errno: 150)  

Extra knowledge

  1. I'm declaring my Entity through annotation in class.
  2. This code is working (but I've to run manually a few operations that are not run after those kind of exception)

What I would like to know

  1. What's causing that bug ?
  2. Is there any way to fix it ? (through Doctrine update for example or some MySQL parameters)
AsTeR
  • 7,247
  • 14
  • 60
  • 99
  • 1
    Try running the DDL SQL in the MySQL CLI (manually) and then run `SHOW ENGINE InnoDB STATUS` for more details. Error 1005 is because of a missing index in the referenced table. – Ocramius Mar 20 '13 at 14:01
  • 1
    This looks like your mysql user does not have create table permissions, but Ocramius's suggestion is necessary for debugging it fully. – Lighthart Mar 20 '13 at 16:45

1 Answers1

0

A suggested by @Ocramius and @Lighthart, this is a pure SQL problem. It came from buggy Doctrine entity declaration generating inconsistent SQL.

he error described in the question was linked with an inconsistency at the columns level, the key was int(11) and the foreign key varchar(255).

AsTeR
  • 7,247
  • 14
  • 60
  • 99