0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

<cloudflare d1>✘ [ERROR] The supplied SQL string contains no statements

Posted at

cloudflare の d1 を使おうとしたがschemaがmigrateできない問題に遭遇。
しかも本番の d1 だと通るが --local にするとなぜかうまくいかない

問題

wranlger d1 execute <db> --local --file=./schema.sql

...

✘ [ERROR] no such column: test

If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose
schema.sql
CREATE TABLE IF NOT EXISTS Users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    last_login DATETIME
);

INSERT INTO Users (username) VALUES ("test");

解消

Insert values のダブルクオーテーションがダメなようです。

これでok

schema.sql
INSERT INTO Users (username) VALUES ('test');

その他

ちなみに Insert を消してもうまくいかない?

schema.sql
CREATE TABLE IF NOT EXISTS Users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT NOT NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    last_login DATETIME
);

これだけだと

[ERROR] The supplied SQL string contains no statements

まとめ

ダブルクオーテーションは識別子(カラム、インデックスなど)として認識されるようで文字列リテラルはシングルクオート使おう!

これはsqlite独自なのか?ormに甘えたい。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?