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

sqlite3 foreign keys which don't name columns can't be inferred #1535

Open
habnabit opened this Issue Feb 4, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@habnabit

habnabit commented Feb 4, 2018

Setup

Versions

  • Rust: rustc 1.25.0-nightly (616b66dca 2018-02-02)
  • Diesel: diesel 1.1.0
  • Database: sqlite3 3.16.0 2016-11-04 19:09:39 0e5ffd9123d6d2d2b8f3701e8a73cc98a3a7ff5f
  • Operating System macOS 10.12.6 (16G1114)

Feature Flags

  • diesel: sqlite postgres

Problem Description

Running diesel print-schema fails, with very terse output:

$ RUST_BACKTRACE=full RUST_LOG=trace diesel print-schema
Unexpected null for non-null column

Steps to reproduce

sqlite> .schema accounts
CREATE TABLE accounts (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  account TEXT NOT NULL,
  data_center_id INTEGER NOT NULL,
  auth_key BLOB NOT NULL,
  UNIQUE (account, data_center_id),
  FOREIGN KEY (data_center_id) REFERENCES data_centers
);
sqlite> .schema data_centers
CREATE TABLE data_centers (
  id INTEGER PRIMARY KEY
);

This produces:

sqlite> PRAGMA FOREIGN_KEY_LIST('accounts');
id          seq         table         from            to          on_update   on_delete   match
----------  ----------  ------------  --------------  ----------  ----------  ----------  ----------
0           0           data_centers  data_center_id  -NULL-      NO ACTION   NO ACTION   NONE

to is NULL because REFERENCES data_centers doesn't name any columns; it's implicitly the same as REFERENCES data_centers(id). I'm pretty sure this is due to the pragma_foreign_key_list pseudo-table doesn't expect a NULL.

table! {
pragma_foreign_key_list {
id -> Integer,
seq -> Integer,
_table -> VarChar,
from -> VarChar,
to -> VarChar,
on_update -> VarChar,
on_delete -> VarChar,
_match -> VarChar,
}
}

Checklist

  • I have already looked over the issue tracker for similar issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment