If you are getting error while importing or restoring the database dump like as mentioned below :
MySQL: Can’t create table ‘./dbname/data.frm’ (errno: 150)
This may come due to foreign key constraints defined in tables. So If in backup file Referencing table is created before the Referenced table than this will throw error. So, in this case, you will need to make MySQL stop checking foreign key constraints while importing/restoring the backup.
So How to resolve it ?
We can resolve it using below commands
You can also debug the issue by using below command if you have Process Privilege on the database.
SHOW ENGINE INNODB STATUS;
If you don’t have the process privilege than you will need to have one otherwise it will show you error like :
[SQL] SHOW ENGINE INNODB STATUS; [Err] 1227 - Access denied; you need (at least one of) the PROCESS privilege(s) for this operation
Other reason can also be involved like:
- Storage engine types are different.
- All referenced keys MUST have either PRIMARY or UNIQUE index.
- Referencing Column MUST have identical data type to the Referenced column.
- Backup using the same constraint name which is already taken by other foreign keys.
- Column Collations Don’t Match.