Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Migration Generator: Foreign keys are created even though they already exist #14

Closed
cebe opened this issue Aug 3, 2020 · 0 comments
Closed
Labels
bug Something isn't working

Comments

@cebe
Copy link
Owner

cebe commented Aug 3, 2020

When a table has been created with foreign keys, the next generator run will include a migration again that adds the same foreign keys.

Example:

<?php

/**
 * Table for Task
 */
class m200803_210003_change_table_tasks extends \yii\db\Migration
{
    public function safeUp()
    {
        $this->addForeignKey('fk_tasks_project_id_projects_id', '{{%tasks}}', 'project_id', '{{%projects}}', 'id');
        $this->addForeignKey('fk_tasks_creator_id_users_id', '{{%tasks}}', 'creator_id', '{{%users}}', 'id');
    }

    public function safeDown()
    {
        $this->dropForeignKey('fk_tasks_creator_id_users_id', '{{%tasks}}');
        $this->dropForeignKey('fk_tasks_project_id_projects_id', '{{%tasks}}');
    }
}

@Insolita You should be able to reproduce this in the layer5 project when running ./yii gii/api.

@cebe cebe added the bug Something isn't working label Aug 3, 2020
@cebe cebe closed this as completed Aug 10, 2020
cebe pushed a commit that referenced this issue Mar 22, 2023
…ete-and-on-update-foreign-key-constraints-in-yii2-open-api-spec-definitions

Resolve: Add ability to add "ON DELETE" and "ON UPDATE" foreign key constraints in yii2-open-api spec definitions
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant