evsign's avatar

something strange with migrations

Hi. When i create new migration with renaming and adding new column then migration was sucсessfully executed, but in table was occurred only renaming without adding. But when i create two separate migration for every action then all ok. Database is sqlite3.

Schema::table('articles', function(Blueprint $table)
    {
        $table->text('description')->default('');
        $table->renameColumn('body','bodyfull');
    });

Why?

0 likes
13 replies
evsign's avatar

Yes. And rollback is working. By the way, when i trying to rollback after the union migration i got a error, becouse column was not created.

JohnRivs's avatar

Can you paste the whole file? In the down method, are you removing a table, or are you removing the columns you're setting in the up method?

evsign's avatar

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class RenameColumnBody extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('articles', function(Blueprint $table)
            {
                $table->text('description')->default('');
                $table->renameColumn('body','bodyfull');
            });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('articles', function(Blueprint $table)
        {
            $table->renameColumn('bodyfull','body');
            $table->dropColumn('description');
        });
    }

}

Sorry, in previous answer i did a mistake about table, but probably you read this befor i edited)

JohnRivs's avatar

Is this one the only migration failing? Try php artisan migrate:reset and start from scratch.

evsign's avatar

Yes. If make that creating migration with migration what i posted above, result in table will be only "id, title, bodyfull, published_at, created_at, updated_at" and all migration was successfull

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateArticlesMigration extends Migration {

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('articles', function(Blueprint $table)
        {
            $table->increments('id');
            
            $table->string('title',100);
            $table->text('body');
            $table->timestamp('published_at');
            $table->timestamps();

            
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('articles');
    }

}


evsign's avatar

Tried just now, result is the same. Also i tried delete database file and run all again, every is the same. Maybe it is a bug?)

JohnRivs's avatar

Is the CreateArticlesMigration running before the RenameColumnBody migration?

evsign's avatar

Yes. Of course.

Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2015_06_02_190216_create_articles_migration
Migrated: 2015_06_03_215756_add_discription_column     ----- migration with renaming and adding new column
JohnRivs's avatar

The description column is not actually being created.

evsign's avatar

Yes. And i tried to add that in next migration with renaming.
First migration -> creating table "articles" with title,body and timestamps
Second migration -> adding description and renaming body in bodyfull

JohnRivs's avatar
Level 37

It's weird, I'm using string instead of text, setting it to nullable just in case. A 'description' field is not being created at all. =/

See if this happens in a MySQL database. I tried using integer too, and it doesn't create the column either. I'm guessing it has something to do with sqlite.

1 like
evsign's avatar

Hmm) You are right) In MySQL all ok) Probably, in sqlite renaming and adding can't be together.
Thanks for reply)

Please or to participate in this conversation.