Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index "primary" contains unknown column "id" #19

Open
leenooks opened this issue Apr 17, 2019 · 4 comments
Open

index "primary" contains unknown column "id" #19

leenooks opened this issue Apr 17, 2019 · 4 comments

Comments

@leenooks
Copy link

So I've noticed an unusual problem - I'm getting the above error when I run a migration that only has:

$table->integer('flag_id')->index();
$table->integer('node_id')->index();

$table->foreign('node_id')->references('id')->on('nodes');
$table->foreign('flag_id')->references('id')->on('flags');

The full SQL that in the error message is SQL: create table "flag_node" ("flag_id" integer not null, "node_id" integer not null, primary key ("id"))

If I run the migration again (without changing anything), the migration succeeds.

It appears as if the migration is remembering the previous migration (if there are multiple updates), where I do have $table->increments('id');

@UedaTakeyuki
Copy link

+1

I've faced same situation with Laravel 5.8.17.

@nbj
Copy link
Owner

nbj commented May 22, 2019

The quick solution here is to split your table creation into its own migration, and adding your constraints afterwards in another migration. I need to rewrite how constraints are handle at table creation time.

@minusmillionaer
Copy link

minusmillionaer commented Jun 17, 2019

I've a migration for an manytomany relation:

Schema::create('project_users', function (Blueprint $table) {
  $table->uuid('project_id')->unsigned();
  $table->uuid('user_id')->unsigned();
});

The driver throw:

Illuminate\Database\QueryException  : SQLSTATE[XX000]: Internal error: 7 ERROR:  index "primary" contains unknown column "id" (SQL: create table "project_users" ("project_id" uuid not null, "user_id" uuid not null, primary key ("id")))

I'm running laravel v5.8.22. The same error is with the laravel default PasswordResetTable.

@nbj
Copy link
Owner

nbj commented Jun 24, 2019

@minusmillionaer My apologies for being stretched so thin on time atm. The quick fix here, should be to just add a primary key to an id column for your pivot tables.

leenooks added a commit to leenooks/cockroachdb-laravel that referenced this issue Jan 1, 2022
…oachDB is very similar

Fix issue with primary keys in migrations issue nbj#23
Fix issue with primary keys in migrations issue nbj#19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants