Answer the question
In order to leave comments, you need to log in
Can't run migrations?
Hello, I can't run migrations
php yii migrate [email protected]/ricco/yii2-ticket/migrations
I'm getting this error, please help me to solve it:.Exception 'yii\db\Exception' with message 'SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
The SQL being executed was: ALTER TABLE `pref_ticket_head` ADD CONSTRAINT `fk_ticket_head` FOREIGN KEY (`user_id`) REFERENCES `pref_user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE'
in /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/db/Schema.php:664
Error Info:
Array
(
[0] => HY000
[1] => 1215
[2] => Cannot add foreign key constraint
)
Stack trace:
#0 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/db/Command.php(1295): yii\db\Schema->convertException(Object(PDOException), 'ALTER TABLE `pr...')
#1 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/db/Command.php(1091): yii\db\Command->internalExecute('ALTER TABLE `pr...')
#2 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/db/Migration.php(467): yii\db\Command->execute()
#3 /var/www/u0598324/public_html/webstels.com/vendor/ricco/yii2-ticket/migrations/m160618_215837_create_ticket_head_table.php(36): yii\db\Migration->addForeignKey('fk_ticket_head', '{{%ticket_head}...', 'user_id', '{{%user}}', 'id', 'CASCADE', 'CASCADE')
#4 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(725): m160618_215837_create_ticket_head_table->up()
#5 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/console/controllers/BaseMigrateController.php(199): yii\console\controllers\BaseMigrateController->migrateUp('m160618_215837_...')
#6 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#7 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#8 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#9 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/console/Controller.php(148): yii\base\Controller->runAction('', Array)
#10 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/base/Module.php(528): yii\console\Controller->runAction('', Array)
#11 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('migrate', Array)
#12 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('migrate', Array)
#13 /var/www/u0598324/public_html/webstels.com/vendor/yiisoft/yii2/base/Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#14 /var/www/u0598324/public_html/webstels.com/yii(20): yii\base\Application->run()
#15 {main}
Answer the question
In order to leave comments, you need to log in
Your problem is that the field you assign the key to has an UNSIGNED attribute. Remove it and you'll be fine!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question