Created
June 12, 2013 13:34
-
-
Save kezabelle/5765278 to your computer and use it in GitHub Desktop.
Apparently Django's add_to_class can magically sidestep the inability to specify fields of the same name (potentially across models?)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from uuid import uuid4 | |
>>> from django.db import models | |
>>> from django.contrib.auth.models import User | |
>>> User.objects.create(username=str(uuid4())) | |
<User: > | |
>>> User.add_to_class('username', models.CharField(max_length=300)) | |
>>> User.objects.create(username=str(uuid4())) | |
Traceback (most recent call last): | |
File "<console>", line 1, in <module> | |
File "/django/db/models/manager.py", line 137, in create | |
return self.get_query_set().create(**kwargs) | |
File "/django/db/models/query.py", line 377, in create | |
obj.save(force_insert=True, using=self.db) | |
File "/django/db/models/base.py", line 463, in save | |
self.save_base(using=using, force_insert=force_insert, force_update=force_update) | |
File "/django/db/models/base.py", line 551, in save_base | |
result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw) | |
File "/django/db/models/manager.py", line 203, in _insert | |
return insert_query(self.model, objs, fields, **kwargs) | |
File "/django/db/models/query.py", line 1593, in insert_query | |
return query.get_compiler(using=using).execute_sql(return_id) | |
File "/django/db/models/sql/compiler.py", line 912, in execute_sql | |
cursor.execute(sql, params) | |
File "/django/db/backends/util.py", line 40, in execute | |
return self.cursor.execute(sql, params) | |
File "/django/db/backends/mysql/base.py", line 114, in execute | |
return self.cursor.execute(query, args) | |
File "/MySQLdb/cursors.py", line 201, in execute | |
self.errorhandler(self, exc, value) | |
File "/MySQLdb/connections.py", line 36, in defaulterrorhandler | |
raise errorclass, errorvalue | |
DatabaseError: (1110, "Column 'username' specified twice") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested against:
Also tried against the GitHub zipball as of django/django@92c49d6