Do you recognise this after running a migration with a foreign key reference in it?
PDOException: SQLSTATE[HY000]: General error: 1005 Can't create table 'my-app.#sql-1_188' (errno: 150) in [..]
While this may not be clear at first, this error can happen if you are trying to add a foreign key. Run the following query to find the latest InnoDB status:
SHOW ENGINE INNODB STATUS ;
The reason why it happens, may differ for each situation, but in the status you can find a lot of information, including the latest error. Note: on busy servers they may not work, but for local development this is a great way to get more details about the problem you are experiencing. A grep from the status:
190223 7:08:59 Error in foreign key constraint of table my@002dapp/#sql-1_188:
foreign key (mod_idt_tld_setting_id
) referencesmod_idt_tld_settings
(id
):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
If an error like this happens, use the following checklist:
- Check the field type.
- Check the length.
- Check the unsigned status.
- Make sure that everything matches for the specific columns in both tables.
In my case, I was referencing a signed integer field to an unsigned integer field.