Reputation: 7977
I have two different table as follows
apis
users
Here users
table has api_id
as a forien key.
Now am executing the following query but it is thorwing error
(stating that the api_id
column references the id
column on the apis
table.)
alter table `users` add constraint users_api_id_foreign foreign key (`api_id`) references `apis` (`id`) on delete cascade on update cascade
Error: #1005 - Can't create table 'xxxxx.#sql-54ef_229ff39' (errno: 150) (<a href="server_engines.php?engine=InnoDB&page=Status&token=50174b3c687a6edcb259e10dd65ca6d7">Details...</a>)
MySQL version (development server)
Server version: 5.5.42-37.1-log
The same query working in my localhost
Server version: 5.5.44-0ubuntu0.14.04.1 - (Ubuntu)
How can I fix this error? Thanks in advance.
Apis Table
Users Table
Upvotes: 0
Views: 63
Reputation: 649
Sometimes this problem is caused by if you already have data in your table.
In your case if you have any data in users
table then first truncate users table and try again.
Upvotes: 1