PHPackages                             lav45/yii2-db-migrate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. lav45/yii2-db-migrate

ActiveYii2-extension[Database &amp; ORM](/categories/database)

lav45/yii2-db-migrate
=====================

This extension allows you to easily create large migrations associated with many foreign keys.

0.4.1.1(6y ago)015.4k↓22.1%1[2 issues](https://github.com/LAV45/yii2-db-migrate/issues)BSD-3-ClausePHP

Since Jun 1Pushed 4y ago2 watchersCompare

[ Source](https://github.com/LAV45/yii2-db-migrate)[ Packagist](https://packagist.org/packages/lav45/yii2-db-migrate)[ Docs](https://github.com/lav45/yii2-db-migrate)[ RSS](/packages/lav45-yii2-db-migrate/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (8)Used By (0)

yii2-db-migrate
===============

[](#yii2-db-migrate)

Это расширение поможет вам избежать конфликтов в вашей SQL db при создании foreign key.

Установка расширения
--------------------

[](#установка-расширения)

```
~$ composer require --prefer-dist lav45/yii2-db-migrate
```

Подключение
-----------

[](#подключение)

```
use lav45\db\MainMigration;

class m000000_000000_init extends MainMigration
{
    // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
    public $defaultTableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

    public function table_news()
    {
        $this->createTable('news', [
            'id' => $this->primaryKey(),
            'author_id' => $this->integer()->notNull(),
            // ...
        ]);

        $this->addForeignKey('news', 'author_id', 'user', 'id', 'SET NULL');
    }

    public function table_news_tag()
    {
        $this->createTable('news_tag', [
            'news_id' => $this->integer()->notNull(),
            'tag_id' => $this->integer()->notNull(),
        ]);

        $this->addPrimaryKey('news_tag', ['news_id', 'tag_id']);

        $this->addForeignKey('news_tag', 'news_id', 'news', 'id');
        $this->addForeignKey('news_tag', 'tag_id', 'tag', 'id');
    }

    public function table_tag()
    {
        $this->createTable('tag', [
            'id' => $this->primaryKey(),
            // ...
        ]);
    }

    public function table_user()
    {
        $this->createTable('user', [
            'id' => $this->primaryKey(),
            // ...
        ]);
    }
}
```

```
~$ php yii migrate/up
Yii Migration Tool (based on Yii v2.0.7-dev)

Creating migration history table "migration"...Done.
Total 1 new migrations to be applied:
        m000000_000000_init

*** applying m000000_000000_init
    > create table user ... done (time: 0.072s)
    > create table news ... done (time: 0.064s)
    > add foreign key news_author_id_fkey: news (author_id) references user (id) ... done (time: 0.001s)
    > create table news_tag ... done (time: 0.001s)
    > add primary key news_tag_pk on news_tag (news_id,tag_id) ... done (time: 0.086s)
    > add foreign key news_tag_news_id_fkey: news_tag (news_id) references news (id) ... done (time: 0.001s)
    > create table tag ... done (time: 0.066s)
    > add foreign key news_tag_tag_id_fkey: news_tag (tag_id) references tag (id) ... done (time: 0.001s)
*** applied m000000_000000_init (time: 0.292s)

1 migrations were applied.

Migrated up successfully.
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~292 days

Recently: every ~432 days

Total

7

Last Release

2251d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/675367?v=4)[Alex](/maintainers/LAV45)[@lav45](https://github.com/lav45)

---

Top Contributors

[![lav45](https://avatars.githubusercontent.com/u/675367?v=4)](https://github.com/lav45 "lav45 (14 commits)")

---

Tags

dbyii2extensionmigrate

### Embed Badge

![Health badge](/badges/lav45-yii2-db-migrate/health.svg)

```
[![Health](https://phpackages.com/badges/lav45-yii2-db-migrate/health.svg)](https://phpackages.com/packages/lav45-yii2-db-migrate)
```

###  Alternatives

[dmstr/yii2-db

Database extensions

19618.8k6](/packages/dmstr-yii2-db)[sjaakp/yii2-spatial

Yii2 ActiveRecord supporting MySQL spatial data

1873.8k1](/packages/sjaakp-yii2-spatial)[mg-code/yii2-helpers

A collection of useful helper classes for Yii framework 2.0

2022.5k5](/packages/mg-code-yii2-helpers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
