(1364, "Field 'id' doesn't have a default value") - mysql issue?

2,539 views
Skip to first unread message

Adam Teale

unread,
Apr 9, 2014, 9:42:35 PM4/9/14
to django...@googlegroups.com
Hi Guys

I have been working on a django app that was going well using an sqlite db.
I've moved it over to mysql and imported the database

Everything looks good

But when I try to use the django comment system that was working well on the sqlite db before I get:

OperationalError at /comments/post/
(1364, "Field 'id' doesn't have a default value")
Request Method: POST
Django Version: 1.6.2
Exception Type: OperationalError
Exception Value:
(1364, "Field 'id' doesn't have a default value")
Exception Location: /Users/admin/Dropbox/mstudio/code/mBrain/mbrain/venv/lib/python2.7/site-packages/MySQLdb/connections.py in defaulterrorhandler, line 36
Python Executable:


I'm a little lost - do i need to set a default value for the django.contrib.comments model?
And how would i do that if I needed to - this has an Object ID field - i don't know how I'd set that up


Any ideas? What am i missing?

Many thanks!

Adam

Mark Furbee

unread,
Apr 9, 2014, 10:46:10 PM4/9/14
to django...@googlegroups.com
You say you imported the database. Did you use syncdb to set up the tables? It sounds like your comment_id field in MySQL is not set as an auto-incrementing primary key field. Do you have access to that MySQL database to check, and or update that field definition?


--
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 post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/18894c72-24c9-41cd-85a1-4dc09072dfb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adam Teale

unread,
Apr 10, 2014, 12:44:44 PM4/10/14
to django...@googlegroups.com
Hello Mark, thanks for responding to my question

I'm using the built-in django commenting system - django.contrib.messages

It was fine with the sqlite db

I had done a syncdb and the app was working, but it just seems that now when I add a comment to something there is this issue.

Do I need to manually add the autofield to my comment subclass?

Thanks!

Adam
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/mBcX6IRYwko/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Adam Teale

unread,
Apr 10, 2014, 12:47:50 PM4/10/14
to django...@googlegroups.com
sorry I meant django.contrib.comments - not messages

Adam Teale

unread,
Apr 10, 2014, 2:04:34 PM4/10/14
to django...@googlegroups.com
ok, i just enabled auto increment to the comment id field

Seems to work fine!

Now is there any way that this could have been set automatically from django? So i don't have this issue in the future)

Thanks!

Adam Teale

unread,
Apr 10, 2014, 2:11:14 PM4/10/14
to django...@googlegroups.com
hmmm it seems that anything in the database is not set to auto increment

C. Kirby

unread,
Apr 10, 2014, 5:35:42 PM4/10/14
to django...@googlegroups.com
When you started using mysql did you do a fresh manage.py syndb or sqlite dump > mysql import? If the latter than you almost certainly have incorrect create statements.

Drop the mysql db and create it using manage.py syncdb. If you need to import the data from the existing sqlite db  I suggest using fixtures

Kirby
Reply all
Reply to author
Forward
0 new messages