Migration with yii2

Hi everyone.

I try to migrate a few changes in mi db but when I use in the command line “php yii migrate” my terminal show me various errors, but I dont understand why.

this is the error that the terminal show me

    Yii Migration Tool (based on Yii v2.0.36)

    Total 1 new migration to be applied:
            m200721_142639_create_documentos_table

    Apply the above migration? (yes|no) [no]:yes
    *** applying m200721_142639_create_documentos_table
    Exception: Function name must be a string (C:\xampp\htdocs\NEMAAPP\console\migrations\m200721_142639_create_documentos_table.php:22)
    #0 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\db\Migration.php(114): m200721_142639_create_documentos_table->safeUp()
    #1 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(727): yii\db\Migration->up()
    #2 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\console\controllers\BaseMigrateController.php(202): yii\console\controllers\BaseMigrateController->migrateUp('m200721_142639_...')
    #3 [internal function]: yii\console\controllers\BaseMigrateController->actionUp(0)
    #4 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array)
    #5 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\base\Controller.php(180): yii\base\InlineAction->runWithParams(Array)
    #6 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\console\Controller.php(181): yii\base\Controller->runAction('', Array)
    #7 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\base\Module.php(528): yii\console\Controller->runAction('', Array)
    #8 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('migrate', Array)
    #9 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('migrate', Array)
    #10 C:\xampp\htdocs\NEMAAPP\vendor\yiisoft\yii2\base\Application.php(386): yii\console\Application->handleRequest(Object(yii\console\Request))
    #11 C:\xampp\htdocs\NEMAAPP\yii(23): yii\base\Application->run()
    #12 {main}
    *** failed to apply m200721_142639_create_documentos_table (time: 0.006s)


    0 from 1 migrations were applied.

    Migration failed. The rest of the migrations are canceled.

in my code have this

    <?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%documentos}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%user}}`
 */
class m200721_142639_create_documentos_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%documentos}}', [
            'id_documento' => $this->string(16)->notNull(),
            'nombre_documento' => $this->string(512)->notNull(),
            'minuta_documento' => $this->text()(),
            'status' => $this->integer(1),
            'thumbnail' => $this->boolean(),
            'fecha_creacion' => $this->timestamp(),
            'upload' => $this->timestamp(),
            'enviado' => $this->timestamp(),
        ]);
        $this->addPrimaryKey("pk_documento_id", "{{%documentos}}", "id_documento");

        // creates index for column `enviado`
        $this->createIndex(
            '{{%idx-documentos-enviado}}',
            '{{%documentos}}',
            'enviado'
        );

        // add foreign key for table `{{%user}}`
        $this->addForeignKey(
            '{{%fk-documentos-enviado}}',
            '{{%documentos}}',
            'enviado',
            '{{%user}}',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%user}}`
        $this->dropForeignKey(
            '{{%fk-documentos-enviado}}',
            '{{%documentos}}'
        );

        // drops index for column `enviado`
        $this->dropIndex(
            '{{%idx-documentos-enviado}}',
            '{{%documentos}}'
        );

        $this->dropTable('{{%documentos}}');
    }
}

,PD: before I doing this migration, have a mistake when I create the fields , I “fix” my mistake creating again the fields with the terminal, Thank you so much for every help that you can give me. (Sorry for my english)

The error is in the 22nd line. Probably 'minuta_documento' => $this->text()(), I guess.

text() instead of text()() ?

2 Likes