K
K
kaxa32012019-06-04 10:07:23
Laravel
kaxa3201, 2019-06-04 10:07:23

How to perform the correct Laravel migration?

There is a written migration

public function up()
    {
        Schema::create('auto', function (Blueprint $table) {
            $table->increments('id');
            $table->string('auto');
            $table->string('uri');
            $table->string('model');
            $table->string('number');
            $table->timestamps();
        });
    }
    public function down()
    {
        Schema::dropIfExists('auto');
    }

i changed some fields, added one field and removed one field.
How can I update this particular table without touching the others?
php artisan migrate:refresh re-creates the entire database
And I need to specifically update the CreateAutoTable migration

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vlad Volodko, 2019-06-04
@kaxa3201

Better, create a new migration and make the changes you need in it, it’s better not to change the already created migration, but there are different cases. Take a look here
https://stackoverflow.com/questions/90505/rollback-one-specific-migration-in-laravel

B
Batyr, 2019-06-05
@batyrserseri

Create a new migration and use the change method

Schema::table('users', function (Blueprint $table) {
    $table->string('name', 50)->change();
});

https://laravel.com/docs/5.8/migrations#columns

J
jazzus, 2019-06-04
@jazzus

You cannot make changes to the migration. You need to create a new one.

// удаляем поле
Schema::table('auto', function (Blueprint $table) {
    $table->dropColumn('remove_field');
});

// добавляем поле
Schema::table('auto', function (Blueprint $table) {
    $table->integer('add_field')->nullable();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question