Django migrate:不创建表

Django migrate : doesn#39;t create tables(Django migrate:不创建表)
本文介绍了Django migrate:不创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一些错误之后,我删除了我的数据库,删除了所有迁移文件(我离开了 init.py).现在,当我跑步时

After some errors, I dropped my database, deleted all my migration files (I left init.py). Now, when I run

python migrate.py makemigrations   // It creates migrations correctly
python migrate.py migrate          // It outputs "app.0001_initial OK"

但绝对NO table(与我的应用相关)是创建的.只有那些与 django 相关的.并且在迁移表中,我的应用程序迁移被标记为已完成但没有创建表,就像我说的那样,非常不愉快.

But absolutely NO table (related to my app) is created. Only those related to django are. And in the migration table, my application migration is marked is done but no table have been created as I said, it's very displeasing.

这是我的迁移文件的摘录:

Here is an excerpt my migration file :

# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-02-18 21:59
from __future__ import unicode_literals

import colorful.fields
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Client',
            fields=[
                ('id', models.AutoField(db_column='idtblclients', primary_key=True, serialize=False)),
                ('genre1', models.CharField(blank=True, max_length=10)),
            ('prenom1', models.CharField(blank=True, max_length=45)),
            ('nom1', models.CharField(blank=True, max_length=45)),
            ('genre2', models.CharField(blank=True, max_length=10)),
            ('prenom2', models.CharField(blank=True, max_length=45)),
            ('nom2', models.CharField(blank=True, max_length=45)),
            ('courriel', models.CharField(blank=True, max_length=45)),
            ('langue', models.CharField(blank=True, max_length=1)),
            ('numtel1', models.CharField(blank=True, db_column='NumTel1', max_length=20)),
            ('numtel2', models.CharField(blank=True, db_column='NumTel2', max_length=20)),
            ('numcivique', models.CharField(blank=True, db_column='NumCivique', max_length=15)),
            ('rue', models.CharField(blank=True, db_column='Rue', max_length=45)),
            ('ville', models.CharField(blank=True, db_column='Ville', max_length=45)),
            ('codepostal', models.CharField(blank=True, db_column='CodePostal', max_length=45)),
            ('timestamp', models.DateTimeField(blank=True, db_column='Timestamp', null=True)),
            ('zone', models.CharField(blank=True, db_column='Zone', max_length=45)),
        ],
        options={
            'db_table': 'tblclients',
            'managed': False,
        },
    ),
....

你知道如何解决它吗?

推荐答案

来自 Django 文档,Options.managed: "如果为 False,则不会对该模型执行数据库表创建或删除操作."

From Django docs, Options.managed: "If False, no database table creation or deletion operations will be performed for this model."

我看到你有

   options={
        'db_table': 'tblclients',
        'managed': False,
    },

尝试在模型中设置 managed=True.

这篇关于Django migrate:不创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)