在生成迁移文件时特别正常,但是迁移到数据库的时候也没有报错,只是没有生成数据表而已,实际问题出现在你的模型语句相关有问题,代码如下:
class Article(models.Model):
id = models.AutoField(primary_key=True, verbose_name='id')
title = models.CharField(max_length=500,verbose_name='文章标题')
username = models.CharField(max_length=100, blank=True, null=True)
text = models.TextField()
date = models.DateTimeField(blank=True, null=True)
tag1 = models.CharField(max_length=255, blank=True, null=True,verbose_name='引言')
type_num = models.CharField(max_length=255, blank=True, null=True)
class Meta:
managed = False
db_table = 'article'
verbose_name = '文章内容'
verbose_name_plural = verbose_name
ordering = ['title']
managed = False 是MySQL不支持的(我猜测)
处理方案:
执行makemigrations后生成迁移文件0001_initial.py,打开将 managed = False注释,如下:
# -*- coding: utf-8 -*-
# Generated by Django 1.11.21 on 2021-07-27 19:04
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Article',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='id')),
('title', models.CharField(max_length=500, verbose_name='文章标题')),
('username', models.CharField(blank=True, max_length=100, null=True)),
('text', models.TextField()),
('date', models.DateTimeField(blank=True, null=True)),
('tag1', models.CharField(blank=True, max_length=255, null=True, verbose_name='引言')),
('type_num', models.CharField(blank=True, max_length=255, null=True)),
],
options={
'verbose_name': '文章内容',
'verbose_name_plural': '文章内容',
'db_table': 'article',
'ordering': ['title'],
# 'managed': False,
},
),
]
注释之后,执行migrate,完成