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

New version is giving this error 'null value in column "deleted_by_cascade" violates not-null constraint' #208

Open
jatindergit opened this issue May 27, 2022 · 5 comments
Labels

Comments

@jatindergit
Copy link

null value in column "deleted_by_cascade" violates not-null constraint
image

@jatindergit jatindergit changed the title New version is giving this error New version is giving this error 'null value in column "deleted_by_cascade" violates not-null constraint' May 27, 2022
@Gagaro Gagaro added the bug label Jun 8, 2022
@Gagaro
Copy link
Member

Gagaro commented Jun 8, 2022

Thanks for the report, could you show me the migration generated to add this column? It should be set to False by default.

@jatindergit
Copy link
Author

jatindergit commented Jun 8, 2022 via email

@anuj9196
Copy link

anuj9196 commented Jul 5, 2022

@Gagaro Here is the migration file generated in my project

    operations = [
        migrations.AddField(
            model_name='question',
            name='deleted_by_cascade',
            field=models.BooleanField(default=False, editable=False),
        ),
    ]

@Gagaro
Copy link
Member

Gagaro commented Jul 22, 2022

Thanks for the migration file.

That's strange, you do have default=False. Could you give me the output of manage.py sqlmigrate of your migration?

@msteffeck
Copy link

msteffeck commented Apr 11, 2023

That's strange, you do have default=False. Could you give me the output of manage.py sqlmigrate of your migration?

You never got a response, but my team just ran into this also.

BEGIN;
--
-- Add field deleted to xxxxxxxxxxx
--
ALTER TABLE "xxxxxxxxxxx" ADD COLUMN "deleted" timestamp with time zone NULL;
--
-- Add field deleted_by_cascade to xxxxxxxxxxx
--
ALTER TABLE "xxxxxxxxxxx" ADD COLUMN "deleted_by_cascade" boolean DEFAULT false NOT NULL;
ALTER TABLE "xxxxxxxxxxx" ALTER COLUMN "deleted_by_cascade" DROP DEFAULT;
CREATE INDEX "xxxxxxxxxxx" ON "xxxxxxxxxxx" ("deleted");
COMMIT;

It appears Django removes the default values from the table after the initial column creation. This is "normal" behavior.
https://stackoverflow.com/questions/42370160/django-postgresql-dropping-column-defaults-at-migrate

I suspect the code in the library (or in our code) is explicitly setting the value to None, so the Django field default is not applied. I will investigate further.

UPDATE:
There is nothing wrong with your code. It was an issue on our end.

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

No branches or pull requests

4 participants