How to remove constraints from my MySQL table?

I want to remove constraints from my table. My query is: ALTER TABLE `tbl_magazine_issue` DROP CONSTRAINT `FK_tbl_magazine_issue_mst_users` But I got an error: #1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘constraint FK_tbl_magazine_issue_mst_users‘ at line 1 11 … Read more

How to find all tables that have foreign keys that reference particular table.column and have values for those foreign keys?

I have a table whose primary key is referenced in several other tables as a foreign key. For example: CREATE TABLE `X` ( `X_id` int NOT NULL auto_increment, `name` varchar(255) NOT NULL, PRIMARY KEY (`X_id`) ) CREATE TABLE `Y` ( `Y_id` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL, `X_id` int DEFAULT NULL, PRIMARY KEY … Read more

Add a reference column migration in Rails 4

A user has many uploads. I want to add a column to the uploads table that references the user. What should the migration look like? Here is what I have. I’m not sure if I should use (1) :user_id, :int or (2) :user, :references. I’m not even sure if (2) works. Just trying to do … Read more

Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths – why?

I’ve been wrestling with this for a while and can’t quite figure out what’s happening. I have a Card entity which contains Sides (usually 2) – and both Cards and Sides have a Stage. I’m using EF Codefirst migrations and the migrations are failing with this error: Introducing FOREIGN KEY constraint ‘FK_dbo.Sides_dbo.Cards_CardId’ on table ‘Sides’ … Read more

Add Foreign Key to existing table

I want to add a Foreign Key to a table called “katalog”. ALTER TABLE katalog ADD CONSTRAINT `fk_katalog_sprache` FOREIGN KEY (`Sprache`) REFERENCES `Sprache` (`ID`) ON DELETE SET NULL ON UPDATE SET NULL; When I try to do this, I get this error message: Error Code: 1005. Can’t create table ‘mytable.#sql-7fb1_7d3a’ (errno: 150) Error in INNODB … Read more