0

I'm currently trying to get familiarized with django and I got stuck with an error I can't fix. My django version is 1.7a2 (from developer).

My model is quite simple:

from django.db import models

class dataset(models.Model):
    ID = models.CharField("ID of current dataset", max_length=20, primary_key=True)
    date = models.DateTimeField('Date of current dataset')
    name = models.CharField("Name of current dataset", max_length=20)
    value = models.FloatField("Value of current dataset")

But when I run 'python manage.py syncdb' command for the second time I get this error:

$ python manage.py syncdb
Operations to perform:
  Synchronize unmigrated apps: admin, contenttypes, auth, sessions
  Apply all migrations: display
Synchronizing apps without migrations:
  Creating tables...
  Installing custom SQL...
  Installing indexes...
Running migrations:
  Applying display.0001_initial...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/core/management/__init__.py", line 427, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/core/management/__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/core/management/base.py", line 287, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/core/management/base.py", line 336, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/core/management/base.py", line 531, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/core/management/commands/syncdb.py", line 22, in handle_noargs
    call_command("migrate", **options)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/core/management/__init__.py", line 167, in call_command
    return klass.execute(*args, **defaults)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/core/management/base.py", line 336, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/core/management/commands/migrate.py", line 145, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/migrations/executor.py", line 60, in migrate
    self.apply_migration(migration, fake=fake)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/migrations/executor.py", line 94, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/migrations/migration.py", line 97, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/migrations/operations/models.py", line 28, in database_forwards
    schema_editor.create_model(model)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/backends/schema.py", line 253, in create_model
    self.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/backends/schema.py", line 95, in execute
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/backends/utils.py", line 77, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/backends/utils.py", line 61, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/utils.py", line 93, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/backends/utils.py", line 61, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django-trunk/django/db/backends/sqlite3/base.py", line 475, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: duplicate column name: ID

Does anyone have any idea what I am doing wrong?

Thanks in advance.

XNor
  • 638
  • 3
  • 8
  • 27
  • Could you check if renaming the `ID` field to, for example, `dataset_id` helps? – alecxe Mar 07 '14 at 20:02
  • I tried renaming the ID to dataset_id and it is showing the same error, again with the ID field instead of the new one :/ – XNor Mar 07 '14 at 20:05

2 Answers2

1

I tried removing the db.sqlite3 file inside my django root directory and it didn't work, but then I removed the content of the /migration/ inside the application folder where my model is and it worked without showing any other error.

It seems to me some kind of bug, since it does not update the migration folder once the model changed...

XNor
  • 638
  • 3
  • 8
  • 27
1

You cannot create an entry with the name ID. Event if you remove ID it will show errors. Here is how I fixed it.

Delete the Migrations Directory Rename ID to some thing else

python manage.py makemigrations python manage.py migrate

Hopefully this will fix it.

xboz
  • 174
  • 1
  • 8