Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Erro em fazer a makemigration da aula 6

apareceu isso quando eu tentei fazer a makemigration no prompt

C:\Users\warli\connectedin>python manage.py makemigration
Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\warli\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "C:\Users\warli\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 347, in execute
    django.setup()
  File "C:\Users\warli\AppData\Local\Programs\Python\Python36\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\warli\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\registry.py", line 112, in populate
    app_config.import_models()
  File "C:\Users\warli\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Users\warli\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\warli\connectedin\perfis\models.py", line 13, in <module>
    class Convite(models.Model):
  File "C:\Users\warli\connectedin\perfis\models.py", line 14, in Convite
    solicitante = models.ForeignKey(Perfil, related_name='convites_feitos')
TypeError: __init__() missing 1 required positional argument: 'on_delete'

aqui o codigo o models.py

from django.db import models

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)

    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')
1 resposta
solução!

Gustavo,

Vc deve estar usando a versão 2.0 ou superior do Django, o curso é baseado na versão:

django==1.7.4

Na documentação do DJANGO:

https://docs.djangoproject.com/en/2.0/ref/models/fields/#django.db.models.ForeignKey.on_delete

"on_delete" se tornará um argumento obrigatório no Django 2.0. Em versões mais antigas, o padrão é CASCADE.