Multiple default values specified for column "id" - django

I use to run my website on my laptop and its database was Sqlite, recently I wanted to transfer it to DigitalOcean and I changed its database to Postgresql, but when I migrate I encounters with some problems.
My Model
class Profil_Eleve(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
statut = models.CharField(max_length=250)
telephone = models.CharField(max_length=250, default="Neant")
niveau = models.CharField(max_length=250)
ecole = models.CharField(max_length=250, default="Neant")
adresse = models.CharField(max_length=250, default="Neant")
eleve_or_etudiant = models.CharField(max_length=250, default="eleve")
Exception:
Traceback (most recent call last):
File "./manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 234, in handle
fake_initial=fake_initial,
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 112, in database_forwards
field,
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 447, in add_field
self.execute(sql, params)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 137, in execute
cursor.execute(sql, params)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 99, in execute
return super().execute(sql, params)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 67, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/abdoulaye/schoollife/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: multiple default values specified for column "id" of table "eleve_profil_eleve"
I don't know what to do

Related

Django migration gives psycopg2.errors.DuplicateTable: relation error

I have previously restored the database for the system, and while i tried to migrate through the django applicaion, the following error is thrown. What is the possible cause and how can we mitigate such cases. I guess the problem is with the existing table conflict, will it solve the issue by delete/dropping the conflicting tables.
Applying introduction.0001_initial...Traceback (most recent call last):
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql)
psycopg2.errors.DuplicateTable: relation "introduction_introduction" already exists
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\core\management\commands\migrate.py", line 231, in handle
post_migrate_state = executor.migrate(
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\migrations\executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\migrations\operations\models.py", line 92, in database_forwards
schema_editor.create_model(model)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\backends\base\schema.py", line 324, in create_model
self.execute(sql, params or None)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\backends\base\schema.py", line 142, in execute
cursor.execute(sql, params)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\backends\utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\HG\Desktop\RC\SB\venv\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "introduction_introduction" already exists```
I had the same problem and solved it by deleting the database a running the inital migrations again

why django models error keeps raising error?

I moved these to models to chat app
class Message(models.Model):
sender = models.ForeignKey(CustomUser, on_delete=models.CASCADE, verbose_name="فرستنده")
receiver = models.ForeignKey(CustomUser, on_delete=models.CASCADE, verbose_name="گیرنده", related_name="reciver")
text = models.CharField("متن", max_length=500)
date_and_time = models.DateTimeField(auto_now_add=True)
subject=models.CharField(max_length=200,verbose_name="موضوع")
notification=models.OneToOneField(Notification,on_delete=models.DO_NOTHING,related_name="message",null=True)
class Meta:
verbose_name = "پیام"
verbose_name_plural = "پیام ها"
class Response(Message):
darkhast_sabt_sherekat = models.ForeignKey(SabteSherkat,on_delete=models.CASCADE,related_name="responses")
After that, it raise an error saying the local id of Response crashed with message I made everything undo and this error keeps coming up
*
Operations to perform:
Apply all migrations: accounts, admin, auth, consultation, contenttypes, sessions, utilities, web
Running migrations:
Applying web.0007_auto_20210815_0831...Traceback (most recent call last):
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 396, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: near ")": syntax error
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/core/management/commands/migrate.py", line 231, in handle
post_migrate_state = executor.migrate(
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/migrations/operations/fields.py", line 178, in database_forwards
schema_editor.remove_field(from_model, from_model._meta.get_field(self.name))
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/sqlite3/schema.py", line 346, in remove_field
self._remake_table(model, delete_field=field)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/sqlite3/schema.py", line 283, in _remake_table
self.execute("INSERT INTO %s (%s) SELECT %s FROM %s" % (
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/base/schema.py", line 142, in execute
cursor.execute(sql, params)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/hamed/sqh-source/venv/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 396, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: near ")": syntax error
*
I deleted every pycache and my DB and even my virtualenv but this error keeps coming up!!!!
Add abstract = True in Message models Meta class, maybe that's the issue.
class Message(models.Model):
class Meta:
verbose_name = "پیام"
verbose_name_plural = "پیام ها"
abstract = True

Saleor migration faild

I tried to install Saleor but during
./manage.py migrate
i get
i made superuser but it doesn't work.
Traceback (most recent call last):
File "./manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/core/management/init.py", line 381, in execute_from_command_line
utility.execute()
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/core/management/init.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/contrib/postgres/operations.py", line 19, in database_forwards
schema_editor.execute("CREATE EXTENSION IF NOT EXISTS %s" % schema_editor.quote_name(self.name))
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 133, in execute
cursor.execute(sql, params)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/utils.py", line 89, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/honza/projects/saleor/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: permission denied to create extension "hstore"
HINT: Must be superuser to create this extension.
solutin is > sudo -i -u postgres; ALTER USER saleor_user WITH SUPERUSER

django wrong in the migration

What is wrong?
C:\holamundo>python manage.py makemigrations App
Migrations for 'App':
App\migrations\0002_auto_20181216_0745.py
- Alter field nombre on tabla
resultado:
C:\holamundo>python manage.py migrate
Operations to perform:
Apply all migrations: App, admin, auth, contenttypes, sessions
Running migrations:
Applying App.0001_initial...Traceback (most recent call last):
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\sqlite3\base.py", line 294, in execute
return Database.Cursor.execute(self, query)
sqlite3.OperationalError: duplicate column name: ID
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\management\base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\core\management\commands\migrate.py", line 203, in handle
fake_initial=fake_initial,
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\migrations\migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\migrations\operations\models.py", line 91, in database_forwards
schema_editor.create_model(model)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\base\schema.py", line 312, in create_model
self.execute(sql, params or None)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\base\schema.py", line 133, in execute
cursor.execute(sql, params)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "C:\Users\kleys\AppData\Local\Programs\Python\Python37\lib\site-packages\django-2.1.3-py3.7.egg\django\db\backends\sqlite3\base.py", line 294, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: duplicate column name: ID
the table:
from django.db import models
# Create your models here.
class tabla (models.Model):
ID = models.PositiveSmallIntegerField()
nombre = models.CharField(max_length=50)
edad = models.PositiveSmallIntegerField()
comida = models.PositiveSmallIntegerField()
cantidad = models.PositiveSmallIntegerField()
def datos(self):
cadena="{0}, {1} {2} {3} {4}"
return cadena.format(self.ID, self.nombre,self.edad,self.comida,self.cantidad)
def __str__(self):
return self.datos()
You need to add primary_key=True if you want to override the id field.
id = models.PositiveIntegerField(primary_key=True)

Migrate command error in Django

I am getting a migrate command error --
django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'module_name' used in key specification without a key length")
The model is
class Coupling(models.Model):
coupling_name = models.CharField(max_length=150, blank=False, default=True, unique=True)
module_name = models.TextField(max_length=255)
There is a key length though.
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\core\management\commands\migrate.py", line 204, in handle
fake_initial=fake_initial,
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\migrations\executor.py", line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\migrations\executor.py", line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\migrations\migration.py", line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\migrations\operations\fields.py", line 204, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\base\schema.py", line 495, in alter_field
old_db_params, new_db_params, strict)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\base\schema.py", line 678, in _alter_field
self.execute(self._create_unique_sql(model, [new_field.column]))
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\base\schema.py", line 112, in execute
cursor.execute(sql, params)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\utils.py", line 79, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\utils\six.py", line 685, in reraise
raise value.with_traceback(tb)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "C:\virtualenvs\ciasenv\lib\site-packages\django\db\backends\mysql\base.py", line 112, in execute
return self.cursor.execute(query, args)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\cursors.py", line 247, in execute
res = self._query(query)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\cursors.py", line 374, in _do_query
db.query(q)
File "C:\virtualenvs\ciasenv\lib\site-packages\MySQLdb\connections.py", line 292, in query
_mysql.connection.query(self, query)
django.db.utils.OperationalError: (1061, "Duplicate key name 'accounts_coupling_coupling_name_175325e1_uniq'")
Any help is highly appreciated. Thanks in advance.
The first error might be because you tried to set unique=True for the TextField. This is not possible for MySQL, as noted in the docs.
The second error is because you are trying to create an index that already exists. This could be because you already ran the migration and it failed part way through. MySQL does not run schema changes in a transaction, so changes aren't rolled back if they fail. You could try dropping the index manually, or, if this is a new project, it might be easier to drop the database and start again.