我正在尝试为我的应用进行迁移。这不是我第一次迁移并一直工作。但这一次似乎它们已经有效,而数据库却没有更新。
这些是我的模特:
class Bambino(models.Model):
nome = models.CharField(max_length=50)
cognome = models.CharField(max_length=50)
data_nascita = models.DateField(auto_now=False, auto_now_add=False)
sesso = models.CharField(max_length=1)
def __unicode__(self):
return self.nome + ' ' + self.cognome + ' ' + self.sesso
class Gioco(models.Model):
nome = models.CharField(max_length=200)
def __unicode__(self):
return self.nome
class Terapia(models.Model):
id_bambino = models.ForeignKey(Bambino, on_delete = models.CASCADE, default='1')
id_gioco = models.ForeignKey(Gioco, on_delete = models.CASCADE, default='1')
nome = models.CharField(max_length=50)
data_inizio = models.DateField(auto_now=False, auto_now_add=False)
data_fine = models.DateField(auto_now=False, auto_now_add=False)
def __unicode__(self):
return self.nome
然后我运行以下命令: python manage.py migrate python manage.py makemigrations(并创建文件0001_initial.py) python manage.py sqlmigrate appname 0001(这里显示数据库中的更改,然后是COMMIT) python manage.py migrate(这次没有发生任何事情)
如果我检查数据库,则不会更新。
这是我的0001_initial.py
中的代码from _future_ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Bambino',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nome', models.CharField(max_length=50)),
('cognome', models.CharField(max_length=50)),
('data_nascita', models.DateField()),
('sesso', models.CharField(max_length=1)),
],
),
migrations.CreateModel(
name='Gioco',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nome', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Terapia',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('nome', models.CharField(max_length=50)),
('data_inizio', models.DateField()),
('data_fine', models.DateField()),
('id_bambino', models.ForeignKey(default='1', on_delete=django.db.models.deletion.CASCADE, to='personal.Bambino')),
('id_gioco', models.ForeignKey(default='1', on_delete=django.db.models.deletion.CASCADE, to='personal.Gioco')),
],
),
]