通过inspectdb创建的模型的makemigrations

时间:2019-11-28 07:09:47

标签: python django

我在Microsoft sql服务器中有一个数据库。我在其中创建了表格和视图。

我运行了py manage.py inspetdb view_Name > Models.py,并用 managed = false 填充了我的models.py文件。我也不希望我的模型改变我的数据库。我只想要它用于数据检索。

我一定要运行迁移/ makemigrations吗?

在inspectdb之后,我应该在我的应用程序上应用makemigrations还是刚刚迁移完成?还有在现有数据库上使用inspectdb时要记住的几点。

在我的models.py文件中,所有列也都有类似以下内容

created = models.DateTimeField(db_column='Created', blank=True, null=True)  # Field name made lowercase

字段名是否小写安全?还是应该像在专栏中一样更改它?那些db_column ='Created',blank = True,null = True字段是什么。并非我所有的观点都有这样的领域。只有少数具有这样的值。

Models.py内容

    # This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#   * Rearrange models' order
#   * Make sure each model has one field with primary_key=True
#   * Make sure each ForeignKey has `on_delete` set to the desired behavior.
#   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models


class test1table(models.Model):
    created = models.DateTimeField(db_column='Created', blank=True, null=True)  # Field name made lowercase.


    class Meta:
        managed = False
        db_table = 'Test1'

迁移文件0001_intial.py

# Generated by Django 2.1.14 on 2019-11-28 07:22

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='test1table',
            fields=[               
                ('created', models.DateTimeField(blank=True, db_column='Created', null=True
            ],
            options={
                'db_table': 'Test1',
                'managed': False,
            },
        ),
    ]

0 个答案:

没有答案
相关问题