The database backend does not accept 0 as a value for AutoField.

609 views
Skip to first unread message

Mayur Bagul

unread,
Apr 26, 2020, 10:22:50 AM4/26/20
to Django users
Hello guys,

im stucked with this error mentioned in subject.
below link redirect details about question.


let me know how to get rid of this problem.


Thanking You.

Antje Kazimiers

unread,
Apr 26, 2020, 11:40:41 AM4/26/20
to django...@googlegroups.com

setting default=False is odd for any field other than a BooleanField. I would take that out for the OneToOneField at least and see how things go.

Antje

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cad442bf-e697-47c6-a0b4-3ce65bcef480%40googlegroups.com.

Divash Singh

unread,
Apr 26, 2020, 12:19:03 PM4/26/20
to django...@googlegroups.com

Think you shouldn’t use false as a default for fields which are not bool

 

Sent from Mail for Windows 10

Mayur Bagul

unread,
Apr 26, 2020, 12:38:21 PM4/26/20
to Django users
Hey thanks for your response i did so because initially at the time of migration it was asking for default value and i just putted false in rush. that filed user from User model returns username as string autofield so what shall i put as default their?
i tried to put None for default value but while migrating it giving same error :-- 

 line 192, in validate_autopk_value
   
raise ValueError('The database backend does not accept 0 as a '
ValueError: The database backend does not accept 0 as a value for AutoField.

guys help me with this error .


On Sunday, April 26, 2020 at 9:10:41 PM UTC+5:30, Antje Kazimiers wrote:

setting default=False is odd for any field other than a BooleanField. I would take that out for the OneToOneField at least and see how things go.

Antje

On 4/26/20 4:19 PM, Mayur Bagul wrote:
Hello guys,

im stucked with this error mentioned in subject.
below link redirect details about question.


let me know how to get rid of this problem.


Thanking You.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

Divash Singh

unread,
Apr 26, 2020, 12:52:34 PM4/26/20
to django...@googlegroups.com

Also,

 

Please make sure that any foreign key fields are not default nulls

 

Sent from Mail for Windows 10

 

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7c34122c-0260-4a5b-8586-42c0037f8192%40googlegroups.com.

 

Divash Singh

unread,
Apr 26, 2020, 12:52:42 PM4/26/20
to django...@googlegroups.com

Once you use the default argument for a model field, it cannot be removed even when u rerun migrations.

 

You need to provide a valid default input value for each specific field

Antje Kazimiers

unread,
Apr 26, 2020, 12:53:39 PM4/26/20
to django...@googlegroups.com

how about adding null=True and blank=True to the field?

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7c34122c-0260-4a5b-8586-42c0037f8192%40googlegroups.com.

Jorge Gimeno

unread,
Apr 26, 2020, 1:09:44 PM4/26/20
to django...@googlegroups.com

I would remove all the default=False options from your model fields in Owner. Re-run migrations, and try to submit the form again.

-Jorge

Divash Singh

unread,
Apr 26, 2020, 2:04:55 PM4/26/20
to django...@googlegroups.com
You can try something like “no value”

Sent from my iPhone

On 26 Apr 2020, at 18:42, Divash Singh <singh...@gmail.com> wrote:



Divash Singh

unread,
Apr 26, 2020, 2:56:38 PM4/26/20
to django...@googlegroups.com

Also,

 

Please make sure that any foreign key fields are not default nulls

 

Sent from Mail for Windows 10

Mayur Bagul

unread,
Apr 29, 2020, 11:05:44 AM4/29/20
to Django users
Hello Guys,

i have try to remove defaut attribute and again try to run migrations it didnt worked .
then i removed all migration files from app and tried running makemigrations it succeed but when trying to migrate it , it giving me error like wont reflect changes in migrations.

im also not getting what default value it should have as  Antj said using null i tried that also it didnt work as Divash singh already said dont keep it null.

after removing default attribute as jlgimeno71   said i did so and now its giving different error :---  1048, "Column 'user_id' cannot be null"

guys if you have any solutions on this please help me with it.

where i have to make changes and what?
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages