#3874 closed (invalid)
setting fk model field to editable=False produces error when using generic create
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Keywords: | delete_object, editable=False | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Given the following model snippet:
class PreferredEmail(models.Model):
label = models.ForeignKey('PreferredEmailLabel')
email = models.EmailField(db_index=True, core=True)
user = models.ForeignKey(User, editable=False, db_index=True, edit_inline=models.TABULAR, num_in_admin=2)
Trying to create a PreferredEmail object using django.views.generic.create_update.delete_object will produce a db error
Traceback (most recent call last):
File "c:\Python24\lib\site-packages\django\core\handlers\base.py" in get_response
77. response = callback(request, *callback_args, **callback_kwargs)
File "c:\Python24\lib\site-packages\django\contrib\auth\decorators.py" in _checklogin
14. return view_func(request, *args, **kwargs)
File "C:\djangosites\AGD\..\AGD\AGDWeb\views.py" in add_email_address
49. return create_object(request, PreferredEmail, post_save_redirect='/accounts/profile/emails/', extra_context={'user': request.user})
File "c:\Python24\lib\site-packages\django\views\generic\create_update.py" in create_object
40. new_object = manipulator.save(new_data)
File "c:\Python24\lib\site-packages\django\db\models\manipulators.py" in save
108. new_object.save()
File "c:\Python24\lib\site-packages\django\db\models\base.py" in save
238. ','.join(placeholders)), db_values)
File "c:\Python24\lib\site-packages\django\db\backends\util.py" in execute
12. return self.cursor.execute(sql, params)
File "c:\Python24\lib\site-packages\MySQLdb\cursors.py" in execute
163. self.errorhandler(self, exc, value)
File "c:\Python24\lib\site-packages\MySQLdb\connections.py" in defaulterrorhandler
35. raise errorclass, errorvalue
OperationalError at /accounts/profile/emails/add/
(1048, "Column 'user_id' cannot be null")
Change History (3)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Unless I'm missing something, that seems like a valid error. You should set null=True on that field.
comment:3 by , 19 years ago
My bad, I thought this option was only supposed to affect the admin interface.
Note:
See TracTickets
for help on using tickets.
Replying to rokclimb15@gmail.com:
That should read django.views.generic.create_update.create_object