Why not triggered migration?

I brought the first migration, and I did, when I wanted to link the table, then I wrote that
No new migrations found. Your system is up-to-date.

All code here is the same table
class m170409_113615_transaction extends Migration
{
 public function up()
{
 $this->createTable('Transaction', [
 'id' => $this->primaryKey(),
 'name' => $this->string(50),
 'category' => $this->integer(),
 'sum' => $this->integer(),
]);

$this->createIndex(
'inx-transaction_category',
'Transaction',
'category'
);

$this->addForeignKey(
'fk_transaction_category',
'category',
'id',
'Transaction',
'category',
'CASCADE'
);
}

 public function down()
{
$this->dropTable('transaction');
}
}

And the second table
class m170409_113632_category extends Migration
{
 public function up()
{
$this->createTable('category',[
 'id' => $this->primaryKey(),
 'name' => $this->string(50),
]);

}

 public function down()
{
$this->dropTable('category');
}
}

I can not understand, as if it should work when you drive in the console yii migrate
June 27th 19 at 14:54
4 answers
June 27th 19 at 14:56
Solution
Show the config of the console application, and specify the exact version of your copy of yii. Also it would be nice to specify what skeleton you are using(basic or advanced).
version 2.0.11 yii basic
if I understand correctly understood config/console.php
<?php

$params = require(__DIR__ . '/params.php');
$db = require(__DIR__ . '/db.php');

$config = [
 'id' =--> 'basic-console',
 'basePath' => dirname(__DIR__),
 'bootstrap' => ['log'],
 'controllerNamespace' => 'app\commands',
 'components' => [
 'cache' => [
 'class' => 'yii\caching\FileCache',
],
 'log' => [
 'targets' => [
[
 'class' => 'yii\log\FileTarget',
 'levels' => ['error', 'warning'],
],
],
],
 'db' => $db,
],
 'params' => $params,
];

if (YII_ENV_DEV) {
 // configuration adjustments for 'dev' environment
 $config['bootstrap'][] = 'gii';
 $config['modules']['gii'] = [
 'class' => 'yii\gii\Module',
];
}

return $config;
- leda commented on June 27th 19 at 14:59
: everything seems OK in the config. if you run the yii migrate command without parameters and get the answer No new migrations found. Your system is up-to-date. maybe your migrations somehow was marked as used? check the table migrations. Note that if after yii migrate, you specify some parameters is quite another matter and then you need to watch what you specify - margarita_Kreiger21 commented on June 27th 19 at 15:02
: So I have stops working after binding the table addForeignKey - leda commented on June 27th 19 at 15:05
in the transaction table - leda commented on June 27th 19 at 15:08
: reread your question. I understand you correctly. You have created the migration. In one migration a transaction table in the second table category. did yii migrate and then finished in one of the migrations code and still want to do yii migrate? - margarita_Kreiger21 commented on June 27th 19 at 15:11
: Yes, I finished addForeignKey to associate a table - leda commented on June 27th 19 at 15:14
: well then it is correct to say that you are new migrations, because you have used them. make
yii migrate/down 2 this command will rollback the last migration 2. not rewrite your migration and will use them again. BE CAREFUL, the COMMAND CANCELS the LAST 2 MIGRATION, I.e. the down()METHOD - margarita_Kreiger21 commented on June 27th 19 at 15:17
June 27th 19 at 14:58
Manually delete the already created table and repeat command
And the link you want to add an already created table, i.e. First apply the second migration
the remark is sound, but the problem of the vehicle that are not migrated. the mechanism of the migrations actually do not care for the content migration. Inside you can write at least rm-rf / thing to rights enough. The problem is that yii does not find migration. - leda commented on June 27th 19 at 15:01
Well, I hope the migration files are created by generating a - margarita_Kreiger21 commented on June 27th 19 at 15:04
: with generate. I made here to specify the foreign key is OK, but to make a connection is not - leda commented on June 27th 19 at 15:07
: delete ALL TABLES (If this is the first and edinstvennye) , and rename the migration m170409_113632_category in m170409_113000_category and the class name do not forget. And run again. Just out of order - leda commented on June 27th 19 at 15:10
June 27th 19 at 15:00
this is the meaning of migration that would not repeat one that has already been used. If you need to make changes, it is necessary to write a new migration and not to make changes to used.
June 27th 19 at 15:02
Migration m170409_113615_transaction trying to create a foreign key on a table that does not exist at the time of execution of migration (created by the migration m170409_113632_category).
MySQL does not support transactions in the DDL and this is creating all constraints better to make a separate migration.
a little sum up as I understand that phrase
MySQL does not support transactions in the DDL and this is creating all constraints better to make a separate migration.

That is, I now better create a new migration to bind tables or not? because I only deal in bales - leda commented on June 27th 19 at 15:05
Yes. Connection create a separate migration AFTER creating all tables.
You have to migrate m170409_113615_transaction successfully created a table Transaction and an index, but when creating a foreign key an error occurred due to the lack of table category. Due to the error migration was not recorded in the database, but the table Transaction has not got no where. And the next attempt to roll this migration is guaranteed to fail.
And if you handle the creation of bundles in a separate migration, is not such a problem. Because locks only the migration with a bunch. - margarita_Kreiger21 commented on June 27th 19 at 15:08

Find more questions by tags Yii