Reputation: 121
I have a simple project here, with two models that contain an attribute called telefone in both.
telefone is phone in portuguese.
Code
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 did the makemigrations and migrate, everything worked as expected, I'm using MySQL as BD.
But for some reason, the phone field is int int in my BD for both the patient table and the medical table, see the image:
Now the other fields are correct, could anyone tell me why this is happening?
EDIT 01:
migrations.CreateModel(
name='Paciente',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nome', models.CharField(max_length=50)),
('endereco', models.CharField(max_length=60)),
('cpf', models.CharField(max_length=11, unique=True)),
('telefone', models.CharField(max_length=15)),
],
),
continue
Upvotes: 0
Views: 49
Reputation: 2279
Delete all the files in yourapp/migrations, except __init__.py
Then run these 2 commands :
python manage.py makemigrations
python manage.py migrate
UPDATE :
If that does not work, delete all tables from MySQL database and let Django recreate them using python manage.py makemigrations
and python manage.py migrate
Upvotes: 2