您现在的代码没有任何问题。我刚刚做了一个 django 项目并运行了它:
型号:
from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User
# Create your models here.
class Juego(models.Model):
nombre_juego = models.CharField(max_length=100)
record = models.DecimalField(max_digits=10000000, decimal_places=3)
fecha_inicio = models.DateTimeField(default=timezone.now)
fecha_fin = models.DateTimeField(default=timezone.now)
enlace = models.CharField(max_length=1000)
class Juegan(models.Model):
user = models.ManyToManyField(User)
nombre_juego = models.ManyToManyField(Juego)
puntuacion = models.DecimalField(max_digits=10000000, decimal_places=3)
迁移 1:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='Juego',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('nombre_juego', models.CharField(max_length=100)),
('record', models.DecimalField(max_digits=10000000, decimal_places=3)),
('fecha_inicio', models.DateTimeField(default=django.utils.timezone.now)),
('fecha_fin', models.DateTimeField(default=django.utils.timezone.now)),
('enlace', models.CharField(max_length=1000)),
],
),
]
迁移 2:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('jugando', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Juegan',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('puntuacion', models.DecimalField(max_digits=10000000, decimal_places=3)),
('nombre_juego', models.ManyToManyField(to='jugando.Juego')),
('user', models.ManyToManyField(to=settings.AUTH_USER_MODEL)),
],
),
]
运行这个:
brendan@brendan-UX305FA:~/Devel/test/juego$ python manage.py makemigrations
Migrations for 'jugando':
0002_juegan.py:
- Create model Juegan
brendan@brendan-UX305FA:~/Devel/test/juego$ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: staticfiles, messages
Apply all migrations: admin, contenttypes, jugando, auth, sessions
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying jugando.0002_juegan... OK
问题必须在您显示的 sn-ps 之外的其他地方:可能是数据完整性问题。如果您还没有任何重要数据,您应该考虑使用新数据库重新开始。