Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yii migrate error #21

Closed
mryndin opened this issue Mar 17, 2018 · 5 comments
Closed

yii migrate error #21

mryndin opened this issue Mar 17, 2018 · 5 comments
Assignees
Milestone

Comments

@mryndin
Copy link

mryndin commented Mar 17, 2018

Hi !

I have table

CREATE TABLE `blog_category`
(
    `id` Int NOT NULL AUTO_INCREMENT COMMENT 'Идентификатор записи',
    `parent_id` Int COMMENT 'Идентификатор родительского элемента',
    `name` Varchar(64) NOT NULL COMMENT 'Наименование категории',
    `tags` Json COMMENT 'Тэги',
    PRIMARY KEY (`id`)
)
COMMENT = 'Категории статей';

CREATE INDEX `parent_name` ON `blog_category` (`parent_id`,`name`) COMMENT 'По родителю в алфавитном порядке';

And generated migration is:

class m180317_090027_create_table_blog_category extends Migration
{
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }

        $this->createTable('{{%blog_category}}', [
            'id' => $this->integer(11)->notNull()->comment('Идентификатор записи')->append('AUTO_INCREMENT PRIMARY KEY'),
            'parent_id' => $this->integer(11)->comment('Идентификатор родительского элемента'),
            'name' => $this->string(64)->notNull()->comment('Наименование категории'),
            'tags' => $this->comment('Тэги'),
        ], $tableOptions);
    }

    public function safeDown()
    {
        $this->dropTable('{{%blog_category}}');
    }
}

When I run "yii migrate", I see:

_Apply the above migrations? (yes|no) [no]: applying m180317_090027_create_table_blog_category
Exception: Calling unknown method: m180317_090027_create_table_blog_category::comment() (E:\www\doreme.spb.ru\vendor\yiisoft\yii2\base\Component.php:300)
#0 E:\www\doreme.spb.ru\console\migrations\m180317_090027_create_table_blog_category.php(18): yii\base\Component->_call('comment', Array)
#1 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\db\Migration.php(114): m180317_090027_create_table_blog_category->safeUp()
#2 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(725): yii\db\Migration->up()
#3 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(199): yii\console\controllers\BaseMigrateController->migrateUp('m180317_090027
...')
#4 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
#5 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
#6 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#7 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\console\Controller.php(148): yii\base\Controller->runAction('', Array)
#8 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('', Array)
#9 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate', Array)
#10 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate', Array)
#11 E:\www\doreme.spb.ru\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
#12 E:\www\doreme.spb.ru\yii(23): yii\base\Application->run()
#13 {main}
failed to apply m180317_090027_create_table_blog_category (time: 0.007s)

WHY ?!

@bizley
Copy link
Owner

bizley commented Mar 17, 2018

Json column is not supported yet, I'm working on this.

@mryndin
Copy link
Author

mryndin commented Mar 17, 2018

And another:
Table:

CREATE TABLE `blog_posts1` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Идентификатор записи',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Время создания',
  `updated_at` timestamp NULL DEFAULT NULL COMMENT 'Время последнего изменения',
  `category` int(11) DEFAULT NULL COMMENT 'Категория поста',
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Наименование поста',
  `content` mediumtext COLLATE utf8_unicode_ci COMMENT 'Содержимое поста',
  `tags` json DEFAULT NULL COMMENT 'Тэги поста',
  `products` json DEFAULT NULL COMMENT 'Продукты поста',
  `published` tinyint(1) DEFAULT '0' COMMENT 'Отметка об опубликованности',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Новости';

Error with field published

@bizley
Copy link
Owner

bizley commented Mar 17, 2018

Same story with tinyint.

@mryndin
Copy link
Author

mryndin commented Mar 17, 2018

I think real migration must be:

        $this->createTable('{{%blog_posts}}', [
            'id'         => $this->integer(11)->notNull()->comment('Идентификатор записи')->append('AUTO_INCREMENT PRIMARY KEY'),
            'created_at' => $this->timestamp()->defaultExpression('CURRENT_TIMESTAMP')->comment('Время создания'),
            'updated_at' => $this->timestamp()->comment('Время последнего изменения'),
            'category'   => $this->integer(11)->comment('Категория поста'),
            'title'      => $this->string(255)->notNull()->comment('Наименование поста'),
            'content'    => $this->text()->comment('Содержимое поста'),
            'tags'       => $this->json()->comment('Тэги поста'),
            'products'   => $this->json()->comment('Продукты поста'),
            'published'  => $this->integer(1)->defaultValue('0')->comment('Отметка об опубликованности'),
        ], $tableOptions);

Thank you for your work !!!

@bizley bizley self-assigned this Mar 26, 2018
@bizley bizley added this to the 2.3.0 milestone Mar 26, 2018
@bizley
Copy link
Owner

bizley commented Mar 29, 2018

Fixed with 2.3.0 release.

@bizley bizley closed this as completed Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants