id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 22672 ManyToMany insert fails with integrity error when a foreign key is empty string leetreveil@… nobody "How to reproduce: {{{#!python class Tag(models.Model): id = models.CharField(_(u'id'), max_length=128, primary_key=True) class Post(models.Model): tags = models.ManyToManyField(Tag, blank=True, null=True) }}} {{{#!python post_obj = Post.objects.get(id='someid') tag_obj = Tag.objects.get(id='') post_obj.tags.add(tag_obj) }}} So when adding a tag object with it's id as a empty string (which is valid) will fail with django.db.utils.IntegrityError: (1048, ""Column 'tag_id' cannot be null""). Looking into the generated sql tag_id is being converted to NULL: {{{ INSERT INTO `post_tags` (`post_id`, `tag_id`) VALUES ('someid', NULL) }}} How do we stop the orm from converting tag_id to NULL and allow it to stay as a empty string?" Uncategorized closed Database layer (models, ORM) 1.6 Normal duplicate Unreviewed 0 0 0 0 0 0