Error while trying to create new field in a model in Django

Asked

Viewed 148 times

0

When trying to create a new field in a model while creating an api, I get the following error when running the command runserver:

inserir a descrição da imagem aqui

That would be the class:

class Person(models.Model):
    teste =  models.CharField(max_length=200, default='')
    name = models.CharField(max_length=200, default='')
    last_name = models.CharField(max_length=200, default='')
    age = models.IntegerField(max_length=100, default='')
    history = HistoricalRecords()

I tried to rotate the python manage.py runserver, initially, also tried to rotate the makemigrations. I believe this error is related to SQL Server, but it was not clear why it occurred. Even filling the field fields in the serializer, the error occurs.

  • After running python Manage.py makemigrations, you ran python.py migrate'?

  • Yes, I have directed migrate, but the error persists.

1 answer

0


Very hard to say right away what it is, it can be a configuration/permission of your SQL server.

If you have any delivery time, I recommend creating the field via SQL, then run a "fake" Migration, so Django gives the field as created.

Isolate the Migration from the field you want to create, in a Migrations file. Then run a command python manage.py migrate seuapp numero_da_migration --fake

Ex: python manage.py migrate venda 0001 --fake

Another tip would be to take Migration’s SQL and run directly, be via Django. Then you would have a more detailed error. To get SQL from Migration follow this tutorial:

https://www.dev2qa.com/how-to-show-sql-query-command-in-django-migration/

  • Thank you! Your reply managed to help me, I managed to run have access to the error details and solved my problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.