За последние 24 часа нас посетили 55528 программистов и 1714 роботов. Сейчас ищет 821 программист ...

Некорректно работают миграции

Тема в разделе "Yii", создана пользователем Dimon2x, 5 мар 2018.

  1. Dimon2x

    Dimon2x Старожил

    С нами с:
    26 фев 2012
    Сообщения:
    2.211
    Симпатии:
    186
    Почему дублируются записи, в таблице article_tag

    555.jpg

    m180304_112835_create_article_table

    PHP:
    1. <?php
    2.  
    3. use yii\db\Migration;
    4.  
    5. /**
    6. * Handles the creation of table `article`.
    7. */
    8. class m180304_112835_create_article_table extends Migration
    9. {
    10.     /**
    11.      * {@inheritdoc}
    12.      */
    13.     public function safeUp()
    14.     {
    15.         $this->createTable('article', [
    16.             'id' => $this->primaryKey(),
    17.             'title' => $this->string(),
    18.             'discription' => $this->text(),
    19.             'content' => $this->text(),
    20.             'date' => $this->date(),
    21.             'image' => $this->string(),
    22.             'viewed' => $this->integer(),
    23.             'user_id' => $this->integer(),
    24.             'status' => $this->integer(),
    25.             'category_id' => $this->integer(),
    26.         ]);
    27.     }
    28.  
    29.     /**
    30.      * {@inheritdoc}
    31.      */
    32.     public function safeDown()
    33.     {
    34.         $this->dropTable('article');
    35.     }
    36. }
    m180304_113659_create_category_table

    PHP:
    1. <?php
    2.  
    3. use yii\db\Migration;
    4.  
    5. /**
    6. * Handles the creation of table `category`.
    7. */
    8. class m180304_113659_create_category_table extends Migration
    9. {
    10.     /**
    11.      * {@inheritdoc}
    12.      */
    13.     public function safeUp()
    14.     {
    15.         $this->createTable('category', [
    16.             'id' => $this->primaryKey(),
    17.             'title' => $this->string()
    18.         ]);
    19.     }
    20.  
    21.     /**
    22.      * {@inheritdoc}
    23.      */
    24.     public function safeDown()
    25.     {
    26.         $this->dropTable('category');
    27.     }
    28. }
    m180304_112914_create_tag_table

    PHP:
    1. <?php
    2.  
    3. use yii\db\Migration;
    4.  
    5. /**
    6. * Handles the creation of table `tag`.
    7. */
    8. class m180304_112914_create_tag_table extends Migration
    9. {
    10.     /**
    11.      * {@inheritdoc}
    12.      */
    13.     public function safeUp()
    14.     {
    15.         $this->createTable('tag', [
    16.             'id' => $this->primaryKey(),
    17.             'title' => $this->string()
    18.         ]);
    19.     }
    20.  
    21.     /**
    22.      * {@inheritdoc}
    23.      */
    24.     public function safeDown()
    25.     {
    26.         $this->dropTable('tag');
    27.     }
    28. }
    m180304_113052_create_article_tag_table

    PHP:
    1. <?php
    2.  
    3. use yii\db\Migration;
    4.  
    5. /**
    6. * Handles the creation of table `article_tag`.
    7. */
    8. class m180304_113052_create_article_tag_table extends Migration
    9. {
    10.     /**
    11.      * {@inheritdoc}
    12.      */
    13.     public function safeUp()
    14.     {
    15.         $this->createTable('article_tag', [
    16.             'id' => $this->primaryKey(),
    17.             'article_id'=>$this->integer(),
    18.             'tag_id'=>$this->integer()
    19.         ]);
    20.         // creates index for column `user_id`
    21.         $this->createIndex(
    22.             'tag_article_article_id',
    23.             'article_tag',
    24.             'article_id'
    25.         );
    26.         // add foreign key for table `user`
    27.         $this->addForeignKey(
    28.             'tag_article_article_id',
    29.             'article_tag',
    30.             'article_id',
    31.             'article',
    32.             'id',
    33.             'CASCADE'
    34.         );
    35.         // creates index for column `user_id`
    36.         $this->createIndex(
    37.             'idx_tag_id',
    38.             'article_tag',
    39.             'tag_id'
    40.         );
    41.         // add foreign key for table `user`
    42.         $this->addForeignKey(
    43.             'fk-tag_id',
    44.             'article_tag',
    45.             'tag_id',
    46.             'tag',
    47.             'id',
    48.             'CASCADE'
    49.         );
    50.     }
    51.  
    52.  
    53.     /**
    54.      * {@inheritdoc}
    55.      */
    56.     public function safeDown()
    57.     {
    58.         $this->dropTable('article_tag');
    59.     }
    60. }
     
  2. mkramer

    mkramer Суперстар
    Команда форума Модератор

    С нами с:
    20 июн 2012
    Сообщения:
    8.600
    Симпатии:
    1.764
    А почему не должны? Ты не уникальный индекс сделал