NeonN
Neon6mo ago
3 replies
dual-salmon

Laravel Migration to Neon Error

When I try to migrate my laravel database to Neon's server, I keep getting this error:

SQLSTATE[25P02]: In failed sql transaction: 7 ERROR:  current transaction is aborted, commands ignored until end of transaction block (Connection: pgsql, SQL: alter table "provinces" add constraint "provinces_country_id_foreign" foreign key ("country_id") references "countries" ("id") on delete cascade)


for context:

I have 2 tables; countries and provinces, to which provinces references countries via country_id like so:

        Schema::create('countries', function (Blueprint $table) {
            $table->id();
        });


        Schema::create('provinces', function (Blueprint $table) {
            $table->id();

            // $table->unsignedBigInteger('country_id');

            $table->foreignId('country_id')->default(1)->constrained('countries')->cascadeOnDelete();

            // $table->foreign('country_id')->references('id')->on('countries')->cascadeOnDelete();

            // $table->foreignId('country_id')->references('id')->on('countries');
        });


The commented code are the attempts at restructuring the foreignId in hopes that it would work. But the thing is, there are other files in my migrations that have foreignId's set like the ones above and they're working fine, here's an example:

Schema::create('users', function (Blueprint $table) {
            $table->id();

            $table->foreignId('user_role_id')->default(1)->constraint('user_roles')->cascadeOnDelete();
            $table->foreignId('user_status_id')->default(1)->constraint('user_statuses')->cascadeOnDelete();
});

        Schema::create('user_roles', function (Blueprint $table) {
            $table->id();

 Schema::create('user_permissions', function (Blueprint $table) {
            $table->id();



All that I'm doing for this error to appear is using the
php artisan migrate:fresh
command in my terminal, or migrating the specific file individually.

yes, the countries migration is running before the provinces.

Any answer is appreciated!
Was this page helpful?