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

🐛 BUG: D1 IDENTITY or AUTOINCREMENT neither work #3744

Open
PeterHindes opened this issue Aug 12, 2023 · 2 comments
Open

🐛 BUG: D1 IDENTITY or AUTOINCREMENT neither work #3744

PeterHindes opened this issue Aug 12, 2023 · 2 comments
Labels
bug Something that isn't working d1 Relating to D1

Comments

@PeterHindes
Copy link

Which Cloudflare product(s) does this pertain to?

D1

What version(s) of the tool(s) are you using?

beta

What version of Node are you using?

No response

What operating system are you using?

windows

Describe the Bug

INSERT's into tables with IDENTITY(0,1) for example don't accept DEFAULT as a value for the column that is taged with IDENTITY
to reproduce try the following on a d1 database
CREATE TABLE emails (id INT IDENTITY(0,1) NOT NULL UNIQUE, email VARCHAR(256) NOT NULL UNIQUE, PRIMARY KEY (id));
INSERT INTO emails (email) VALUES ('test@example.com');
or
INSERT INTO emails (id, email) VALUES (DEFAULT, 'test@example.com');
or
INSERT INTO emails (id, email) VALUES (NULL, 'test@example.com');

None of these inserts behave as expected. I expect them to create the new row and set an appropriate id by incrementing on the largest value (or starting with the provided 0 value for the first insert) but they don't.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

Mapping SQL input into an array of statements
🌀 Parsing 1 statements
🌀 Executing on ...:

X [ERROR] A request to the Cloudflare API (/accounts/.../d1/database/.../query) failed.

NOT NULL constraint failed: emails.id [code: 7500]

@PeterHindes PeterHindes added the bug Something that isn't working label Aug 12, 2023
@PeterHindes PeterHindes changed the title 🐛 BUG: 🐛 BUG: D1 IDENTITY or AUTOINCREMENT neither work Aug 12, 2023
@PeterHindes
Copy link
Author

as for AUTOINCREMENT it is simply not supported for some reason. even though it is in the demo on the d1 workers docs.

@jide
Copy link

jide commented Sep 5, 2023

Found out it works if AUTOINCREMENT is at the end :

-- Create groups table
CREATE TABLE groups (
    id integer PRIMARY KEY AUTOINCREMENT,
    name VARCHAR(255) NOT NULL
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working d1 Relating to D1
Projects
None yet
Development

No branches or pull requests

4 participants