Using INSERT IGNORE with MySQL to prevent duplicate key errors
INSERT IGNORE INTO mytable
(primaryKey, field1, field2)
VALUES
('abc', 1, 2),
('def', 3, 4),
('ghi', 5, 6);
INSERT IGNORE INTO mytable
(primaryKey, field1, field2)
VALUES
('abc', 1, 2),
('def', 3, 4),
('ghi', 5, 6);
I had a little problem with SqlAlchemy and foreign keys. I found in logs information about MySQL errno 150.
Below are some steps to rapair it ;)
mysql> SHOW ENGINE INNODB STATUS ; ------------------------ LATEST FOREIGN KEY ERROR ------------------------ 090506 11:57:34 Error in foreign key constraint of table some_table/t23_aluno: there is no index in the table which would contain the columns as the first columns, or the data types in the table do not match to the ones in the referenced table or one of the ON ... SET NULL columns is declared NOT NULL. Constraint mysql> SET foreign_key_checks = 0; mysql> ALTER TABLE table_name DROP FOREIGN KEY some_foreign_key; mysql> ALTER TABLE table_name DROP INDEX some_index; mysql> ALTER TABLE table_name ADD CONSTRAINT foreign_key_name FOREIGN KEY (etr_id) REFERENCES email_translations (id); mysql> SET foreign_key_checks = 1;