0

When i do:

app/console d:s:u --dump-sql

it shows me

ALTER TABLE coupon ADD CONSTRAINT FK_64BF3F02A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;

That is ok, so i try to execute:

app/console d:s:u --dump-sql --force

and it shows me:

ALTER TABLE coupon ADD CONSTRAINT FK_64BF3F02A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;

Updating database schema...
Database schema updated successfully! "1" queries were executed

i try to check if all is ok and execute:

app/console d:s:u --dump-sql

and it again shows me:

ALTER TABLE coupon ADD CONSTRAINT FK_64BF3F02A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;

what can be the problem? i have no errors, but also no result.

create table after all manipulations from mysql:

CREATE TABLE `coupon` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `code` varchar(255) NOT NULL DEFAULT '',
  `months` tinyint(1) NOT NULL,
  `billed` tinyint(1) NOT NULL DEFAULT '1' COMMENT 'Require CC details or not',
  `email` varchar(255) DEFAULT NULL,
  `first_name` varchar(255) DEFAULT NULL,
  `last_name` varchar(255) DEFAULT NULL,
  `user_id` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `used_at` datetime DEFAULT NULL,
  `expired_at` datetime DEFAULT NULL,
  `deleted` tinyint(1) NOT NULL DEFAULT '0',
  `multiuser` tinyint(1) NOT NULL DEFAULT '0',
  `days` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `IDX_64BF3F02A76ED395` (`user_id`)
) ENGINE=MyISAM AUTO_INCREMENT=7154 DEFAULT CHARSET=utf8
kRicha
  • 797
  • 9
  • 27

1 Answers1

1

The problem is the engine which you use in your table. MyISAM is not capable of storing foreign keys and MySQL just silently ignores any SQL which tries to add them. I suggest using InnoDB as an engine in general for all columns (see MyISAM versus InnoDB for the difference)

ALTER TABLE `coupon` ENGINE = InnoDB ;

Then you can execute the foreign key sql again

ALTER TABLE `coupon` 
ADD CONSTRAINT `FK_64BF3F02A76ED395`
FOREIGN KEY (`user_id`)
REFERENCES `user` (`id`)
ON DELETE CASCADE
ON UPDATE CASCADE;
Community
  • 1
  • 1
Iarwa1n
  • 460
  • 3
  • 12