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

Can't use CLI to migrate and create composite primary key table #1779

Closed
losvedir opened this Issue Jul 7, 2018 · 2 comments

Comments

Projects
None yet
3 participants
@losvedir

losvedir commented Jul 7, 2018

Setup

This is my up.sql:

create table vehicle_movements (
  vehicle_id varchar not null,
  stop_id varchar not null,
  arrived_at int,
  departed_at int,
  primary key (vehicle_id, stop_id)
)

This is what happens when I try to migrate:

➜  hawkeye git:(master) ✗ diesel migration run
Diesel only supports tables with primary keys. Table vehicle_movements has no primary key

But I do have a primary key - a composite one, specified at the end of the create table. I see from #450 that supposedly there is support for composite primary keys, so I don't know if I'm doing something wrong or not.

Versions

  • Rust: 1.27.0
  • Diesel: crate - 1.3.2, CLI - 1.3.1
  • Database: Postgres 10
  • Operating System OS X

Feature Flags

  • diesel: --without-default-features --feature postgres

Checklist

  • I have already looked over the issue tracker for similar issues.
  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
@nocduro

This comment has been minimized.

nocduro commented Jul 24, 2018

I had this problem as well, here's how to reproduce:

  • try to run migration on table without primary key:
create table vehicle_movements (
  vehicle_id varchar not null,
  stop_id varchar not null,
  arrived_at int,
  departed_at int
)
  • get error message
  • edit up.sql to include composite key:
create table vehicle_movements (
  vehicle_id varchar not null,
  stop_id varchar not null,
  arrived_at int,
  departed_at int,
  primary key (vehicle_id, stop_id)
)
  • diesel migration run then fails with the same error

I fixed it by running diesel migration revert which dropped the tables, and then re-running diesel migration run

@sgrif

This comment has been minimized.

Member

sgrif commented Jul 25, 2018

The above comment is likely correct. It sounds like you edited a migration without re-running it, or your schema for some other reason does not match what you expect it to be.

@sgrif sgrif closed this Jul 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment