简体   繁体   中英

SQL error key column does not exist when importing into EC2

I'm building an SQL database in PHPMyAdmin and importing it into SQL Server on EC2. When I import the database I get an error saying:

ERROR 1072 (42000) at line 119: Key column 'des_code_lot' doesn't exist in table

I went to line 119 and found:

ALTER TABLE lot
ADD CONSTRAINT des_code_lot FOREIGN KEY (des_code_lot) REFERENCES destination (des_code);` 

Earlier in the SQL code I had:

CREATE TABLE IF NOT EXISTS lot ( des_code_lot int(11) NOT NULL,
...

I thought this created the column in the table lot.

I already have the tables on InnoDB.

Is there anyway I can get around this in phpmyadmin?

Also, is there an easier way to set up a SQL database on EC2 that involves foreign keys without having to export/import SQL files?

My guess is that the constraint was not added since there is already a column with that name.

Change this: ALTER TABLE lot ADD CONSTRAINT des_code_lot FOREIGN KEY (des_code_lot) REFERENCES destination (des_code);

To this: ALTER TABLE lot ADD CONSTRAINT fk_des_code_lot FOREIGN KEY (des_code_lot) REFERENCES destination (des_code);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM