Mihir Trivedi
Mihir Trivedi

Reputation: 41

Not able to migrate new table in laravel

I've created a table using command

create table: php artisan make:migration create_movie --create=movie

then added body & user_id columns to code

public function up()
{
    Schema::create('movie', function (Blueprint $table) {

        $table->increments('id');

        $table->text('body');

        $table->integer('user_id');

        $table->timestamps();
    });
}

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

then hit php artisan migrate command

but this is showing me this exception and I'm not able to add movie table to the database

[Illuminate\Database\QueryException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists (SQL: create table users ( id int unsigned not null auto_increment primary key, name varchar(255) not null, email varchar(255) not null, password varchar(255) not null, remember_token varchar(100) null, created_at timestamp null, updated_at tim estamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)

[PDOException] SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists

Upvotes: 0

Views: 1626

Answers (4)

Xan Pena
Xan Pena

Reputation: 16

You can use the next artisan command that will roll back all of your migrations and then execute the migrate command. Please, check de documentation here https://laravel.com/docs/8.x/migrations#roll-back-migrate-using-a-single-command

php artisan migrate:fresh

Upvotes: 0

AddWeb Solution Pvt Ltd
AddWeb Solution Pvt Ltd

Reputation: 21681

Please empty migrations table and run php artisan migrate command

OR

Create test folder in migrations folder then newly created migration moved/copied in test folder and run below command in your terminal/cmd like:

php artisan migrate --path=/database/migrations/test/

Upvotes: 0

bipin patel
bipin patel

Reputation: 2111

You can try run new generate movie specific file migration like this

php artisan migrate --path=/database/migrations/{{Your_movie_migration_filename}}

Upvotes: 0

Onix
Onix

Reputation: 2179

Empty database tables and run migration again or if you do not want to lose your data do the follow:

Find your movie table migration (Database>Migrations) and change the date to any oldest date on the migration file so that it goes first in the folder.

Run migration again, even if you get error about users table (its not error, its just saying that it already exist) the movie table will be created.

Migration migrates from top to bottom

Upvotes: 0

Related Questions