3

In Connection.php line 664:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'credit_prop_fees' already exists (SQL: create table credit_prop_fees (id int unsigned not null auto_increment primary key, fee_id int not null, created_at timestamp null, updated_at timestamp null) default character set utf8mb4 collate utf8mb4_unicode_ci)

I have two migrations one by another few This is firs one

public function up()
    {
        Schema::create('credit_prop_fees', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('fee_id');


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

As you see in the next migration I have dropeIfExist() function

public function up()
    {
        Schema::dropIfExists('credit_prop_fees');

        Schema::create('credit_prop_fees', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('credit_id');
            $table->integer('credit_prop_id');
            $table->integer('fee_type_id');
            $table->integer('fee_value_id');
            $table->timestamps();
        });
    }

I am trying to make php artisan migrate Why I receive this error if I write Schema::dropIfExists('credit_prop_fees');

Even When I use tinker I have null but the table deleted C:\OSPanel\domains\laravel.bai.loc>php artisan tinker Psy Shell v0.8.17 (PHP 7.1.12 — cli) by Justin Hileman

Schema::drop('credit_prop_fees'); => null

Thanks for your answers

David
  • 181
  • 1
  • 2
  • 8
  • why you are using two scema for same table and schema drop on your up method?? – Sohel0415 Jan 12 '18 at 18:41
  • 1
    If you try to run "php artisan migrate:status", is your second migration AFTER the first one? The first migration may be running after the second one, therefore not trying to drop the table. – user1453870 Jan 12 '18 at 21:21

3 Answers3

4

I don't know why you are dropping new created table, But try :

php arisan migrate:fresh
Mahdi Younesi
  • 6,889
  • 2
  • 20
  • 51
0

Same to me, I solved it by : Use !Schema::hasTable('credit_prop_fees'), it will check whether a table already exists in the database or not.

if (!Schema::hasTable('credit_prop_fees')) {
    Schema::create('credit_prop_fees', function (Blueprint $table) {
        $table->increments('id');
            $table->integer('credit_id');
            $table->integer('credit_prop_id');
            $table->integer('fee_type_id');
            $table->integer('fee_value_id');
            $table->timestamps();
    });
}

Reference of answer is here:

[https://stackoverflow.com/questions/46129270/laravel-5-5-error-base-table-or-view-already-exists-1050-table-users-already][1]
shaza
  • 37
  • 11
0

It is php artisan migrate:fresh not php arisan migrate:fresh.