mysql - Alter table throw error #1005 -


i have 2 different table follows

apis users 

here users table has api_id forien key.

now executing following query thorwing error (stating api_id column references id column on 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&amp;page=status&amp;token=50174b3c687a6edcb259e10dd65ca6d7">details...</a>)

mysql version (development server)

server version: 5.5.42-37.1-log 

the same query working in localhost

server version: 5.5.44-0ubuntu0.14.04.1 - (ubuntu) 

how can fix error? in advance.

apis table

enter image description here

users table

enter image description here

sometimes problem caused if have data in table. in case if have data in users table first truncate users table , try again.


Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -