Tudo apareceu como previsto até dar o python manage.py migrate
Seguem as mensagens de erro:
C:\Dev\Alura\Django\connectedin>python manage.py migrate
Operations to perform:
Apply all migrations: admin, contenttypes, perfis, auth, sessions
Running migrations:
Applying perfis.0004_auto_20161226_2252...Traceback (most recent call last):
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 37, in database_forwards
field,
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\schema.py", line 176, in add_field
self._remake_table(model, create_fields=[field])
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\schema.py", line 144, in _remake_table
self.quote_name(model._meta.db_table),
File "C:\Python27\lib\site-packages\django\db\backends\schema.py", line 102, in execute
cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\Python27\lib\site-packages\django\db\backends\utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "C:\Python27\lib\site-packages\django\db\backends\sqlite3\base.py", line 485, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.IntegrityError: column usuario_id is not unique
Segue models.py do módulo perfis, o de usuários está em branco:
# connectedin/perfis/models.py
from django.db import models
from django.contrib.auth.models import User
class Perfil(models.Model):
nome = models.CharField(max_length=255, null=False)
email = models.CharField(max_length=255, null=False)
telefone = models.CharField(max_length=15, null=False)
nome_empresa = models.CharField(max_length=255, null=False)
contatos = models.ManyToManyField('self')
usuario = models.OneToOneField(User, related_name="perfil")
@property
def email(self):
return self.usuario.email
def convidar(self, perfil_convidado):
Convite(solicitante=self, convidado=perfil_convidado).save()
class Convite(models.Model):
solicitante = models.ForeignKey(Perfil, related_name="convites_feitos")
convidado = models.ForeignKey(Perfil, related_name="convites_recebidos")
def aceitar(self):
self.convidado.contatos.add(self.solicitante)
self.solicitante.contatos.add(self.convidado)
self.delete()
Alguma ideia do que pode estar acontecendo e como corrigir, se for o caso?
TIA,
WB::