Django - Charfield creates Int field in BD

Asked

Viewed 55 times

0

I have a simple project here, with two models that contain an attribute called phone in both.

class Medico (models.Model):
    nome = models.CharField(max_length=50)
    endereco = models.CharField(max_length=60)
    cpf = models.CharField(unique=True, max_length=11)
    telefone = models.CharField(max_length=15)
    especialidade = models.ForeignKey(Especialidade, on_delete=models.CASCADE)

    def __str__(self):
        return self.nome

class Paciente (models.Model):
    nome = models.CharField(max_length=50)
    endereco = models.CharField(max_length=60)
    cpf = models.CharField(unique=True, max_length=11)
    telefone = models.CharField(max_length=15)

    def __str__(self):
        return self.nome

I made the makemigrations and migrate, everything worked as planned, I am using the Mysql like comics.

But for some reason, the countryside telephone is as int in my BD for both the patient table and the medical table, see in the image:

inserir a descrição da imagem aqui

Already the other fields are correct, someone would tell me why this is happening?

1 answer

0


With the increase of files in the folder in your app/Migrations directory/pychache, may cause some conflicts when migrating to the database.

In this case, you have two ways to solve.

First form:

  • Delete all files from your app/Migrations folder/pychache (WITH EXCEPTION OF THE FILE init.py)
  • Run the following commands: python manage.py makemigrations and python manage.py migrate.

This can solve the problem.

Already in my case, the hole was lower, I had to delete the entire database, delete the files mentioned in step 1 and later recreate the database.

Explaining Second Way: (solved my problem)

  • Delete the database
  • Delete all files from your app/Migrations folder/pychache (WITH EXCEPTION OF THE FILE init.py)
  • Create the Bank again
  • Run the following commands: python manage.py makemigrations and python manage.py migrate.

Browser other questions tagged

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