diesel: [cli] MySQL Diesel only supports tables with primary keys.

Setup

set DATABASE_UR with DB server URL.

Make new migration which contents:

CREATE TABLE junk (
    id BIGINT(20) UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    something VARCHAR(20)
);

– OR –

CREATE TABLE junk (
    id BIGINT(20) UNSIGNED AUTO_INCREMENT NOT NULL,
    something VARCHAR(20),
    PRIMARY KEY (id)
);

– OR –

Any other valid SQL syntax to make a table with a PRIMARY KEY

Versions

  • Rust: rustc 1.52.1 (9bc8c42bb 2021-05-09)
  • Diesel CLI: v1.4.1
  • Database: mysql Ver 8.0.25 for Win64 on x86_64 (MySQL Community Server - GPL)
  • Windows 10

Problem Description

do: diesel migration run

What is the expected output?

Running migration 2021-05-18-193949_junk

What is the actual output?

Running migration 2021-05-18-193949_junk
Diesel only supports tables with primary keys. Table junk has no primary key

Checklist

  • [x ] I have already looked over the issue tracker and the disussion forum for similar possible closed issues.
  • [ x] This issue can be reproduced on Rust’s stable channel. (Your issue will be closed if this is not the case)
  • [x ] This issue can be reproduced without requiring a third party crate

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 52 (16 by maintainers)

Most upvoted comments

@COREjake This issue is about a mysql specific problem. Your comment about postgres specific problems seems to be not right here. Please do not add these off-topic comments to existing issues.

@zdannar If you have a reproducible container that would be really helpful.

Otherwise, I assume that this is caused by a changed way how mysql updates the information_schema. If it’s a purely time based thing, that might be fixable by just adding a small amount of “sleep time” in the right place. Otherwise it could require reopening the connection at all. Testing that would require code modifications and trying out a few variants. If someone is interested in that, this would be a good entry point: https://github.com/diesel-rs/diesel/blob/4fe987676e7c465f2fdc116fdf11ba4378e64f9a/diesel_cli/src/main.rs#L69-L73 I would probably just start with adding a std::thread::sleep_ms(1000) there between line 72 and 73.

Other than that I can say that variant 3 from @jmqd’s list is quite likely not the cause, as there is just no parallelism there. We execute the migrations one by one in order and afterwards the schema file is regenerated.

I now believe this is possibly a race condition of some sort, potentially with the information_schema being populated?

See here how it is not deterministic:

[ec2-user@ip-REDACTED]$ diesel migration redo
Rolling back migration 2021-11-28-110249_initial
Running migration 2021-11-28-110249_initial
Diesel only supports tables with primary keys. Table goals has no primary key

[ec2-user@ip-REDACTED]$ diesel migration redo
Rolling back migration 2021-11-28-110249_initial
Running migration 2021-11-28-110249_initial

One thing I should note: I’m on ARM.