Reputation: 65
I am trying to include the following schema to my django app, but always wind up getting an Assertion Error. The schema:
class Tuple(models.Model):
fancyId = models.IntegerField()
file1 = models.FileField()
file2 = models.FileField()
ccode1 = models.CharField(max_length=10000,default="123",unique=False)
I even tried using the same example as given in the django docs, but wind up with the same error!
The error thrown is this:
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 338, in execute
output = self.handle(*args, **options)
File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 102, in apply_migration
migration.apply(project_state, schema_editor)
File "C:\Python27\lib\site-packages\django\db\migrations\migration.py", line 108, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
File "C:\Python27\lib\site-packages\django\db\migrations\operations\fields.py", line 29, in database_forwards
to_model = to_state.render().get_model(app_label, self.model_name)
File "C:\Python27\lib\site-packages\django\db\migrations\state.py", line 67, in render
model.render(self.apps)
File "C:\Python27\lib\site-packages\django\db\migrations\state.py", line 316, in render
body,
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 168, in __new__
new_class.add_to_class(obj_name, obj)
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 297, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 919, in contribute_to_class
"A model can't have more than one AutoField."
AssertionError: A model can't have more than one AutoField.
Upvotes: 2
Views: 4248
Reputation: 176
Django will automatically generate the primary key id
, so the Id
is redundant. see the Django Book.
Unless you are trying to integrating Django with a legacy database. see docs.
Upvotes: 4