Skip to content

migrate:refresh failed on create_wallets_table #400

@mudzao

Description

@mudzao

hi, i'm trying to do a migration refresh of all my tables but the wallets_table is giving an issue as below. can you help on this?

λ php artisan migrate:rollback
Rolling back: 2018_11_15_124230_create_wallets_table

Illuminate\Database\QueryException

SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails (SQL: drop table wallets)

at C:\laragon\www\jom\vendor\laravel\framework\src\Illuminate\Database\Connection.php:703
699▕ // If an exception occurs when attempting to run a query, we'll format the error
700▕ // message to include the bindings with SQL, which will make this exception a
701▕ // lot more helpful to the developer instead of just the database's errors.
702▕ catch (Exception $e) {
➜ 703▕ throw new QueryException(
704▕ $query, $this->prepareBindings($bindings), $e
705▕ );
706▕ }
707▕ }

1 C:\laragon\www\jom\vendor\laravel\framework\src\Illuminate\Database\Connection.php:492
PDOException::("SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails")

2 C:\laragon\www\jom\vendor\laravel\framework\src\Illuminate\Database\Connection.php:492
PDOStatement::execute()

fyi i didnt modify the migration file, still as below:

public function up(): void
{
Schema::create($this->table(), function (Blueprint $table) {
$table->bigIncrements('id');
$table->morphs('holder');
$table->string('name');
$table->string('slug')->index();
$table->string('description')->nullable();
$table->json('meta')->nullable();
$table->decimal('balance', 64, 0)->default(0);
$table->unsignedSmallInteger('decimal_places')->default(2);
$table->timestamps();

        $table->unique(['holder_type', 'holder_id', 'slug']);
    });

    Schema::table($this->transactionTable(), function (Blueprint $table) {
        $table->foreign('wallet_id')
            ->references('id')
            ->on($this->table())
            ->onDelete('cascade')
        ;
    });
}

public function down(): void
{
    Schema::drop($this->table());
}

protected function table(): string
{
    return (new Wallet())->getTable();
}

private function transactionTable(): string
{
    return (new Transaction())->getTable();
}

Metadata

Metadata

Assignees

Labels

StalebugSomething isn't workinggood issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions