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

FK column unique not working #326

Open
Prof1-web opened this issue Dec 15, 2023 · 0 comments
Open

FK column unique not working #326

Prof1-web opened this issue Dec 15, 2023 · 0 comments

Comments

@Prof1-web
Copy link

My models:

class User(Model):
    id = fields.BigIntField(pk=True)


class Client(Model):
    id = fields.BigIntField(pk=True)
    user = fields.ForeignKeyField("models.User", on_delete=fields.OnDelete.NO_ACTION, unique=True)

For this models aerich generate:

CREATE TABLE IF NOT EXISTS "users" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS "clients" (
    "id" BIGSERIAL NOT NULL PRIMARY KEY,
    "user_id" BIGINT NOT NULL REFERENCES "users" ("id") ON DELETE NO ACTION
);
CREATE TABLE IF NOT EXISTS "aerich" (
    "id" SERIAL NOT NULL PRIMARY KEY,
    "version" VARCHAR(255) NOT NULL,
    "app" VARCHAR(100) NOT NULL,
    "content" JSONB NOT NULL
);

I am expecting unique constraint on the user_id column, but aerich is ignoring it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant