模型覆盖另一个模型

时间:2019-07-18 06:43:34

标签: python django django-mysql

我已经在数据库中创建了一个表“进攻”,该表可以正常工作,它具有一个名为“ id”的主键

现在,我想创建另一个名称为encen_category的表。并想要创建一个指向表“ offences”中的“ id”的外键

但是,当我进行迁移时,“进攻”表会被Attack_category表覆盖...

所有进攻领域都消失了。它显示了具有相同名称“进攻”的encen_category字段,并且数据库中没有反映encem_category表。

我在xampp服务器上使用mySQL

models.py

from django.db import models
from django.contrib.auth.models import UserManager
from django.core.validators import int_list_validator


# Create your models here.

class Offenses(models.Model):
    id = models.IntegerField(primary_key=True)
    description = models.CharField(null=False, max_length=200)
    assigned_to = models.CharField(null=True, max_length=100)
    categories = models.TextField(null=True)
    category_count = models.IntegerField(null=True)
    policy_category_count = models.IntegerField(null=True)
    security_category_count = models.IntegerField(null=True)
    close_time = models.TimeField(null=True)
    closing_user = models.IntegerField(null=True)
    closing_reason_id = models.IntegerField(null=True)
    credibility = models.IntegerField(null=True)
    relevance = models.IntegerField(null=True)
    severity = models.IntegerField(null=True)
    magnitude = models.IntegerField(null=True)
    destination_networks = models.TextField(null=True)
    source_network = models.CharField(null=True, max_length=100)
    device_count = models.IntegerField(null=True)
    event_count = models.IntegerField(null=True)
    flow_count = models.IntegerField(null=True)
    inactive = models.BooleanField(null=True)
    last_updated_time = models.DateTimeField(null=True)
    local_destination_count = models.IntegerField(null=True)
    offense_source = models.IntegerField(null=True)
    offense_type = models.IntegerField(null=True)
    protected = models.BooleanField(null=True)
    follow_up = models.BooleanField(null=True)
    remote_destination_count = models.IntegerField(null=True)
    source_count = models.IntegerField(null=True)
    start_time = models.TimeField(null=True)
    status = models.CharField(null=True, max_length=100)
    username_count = models.IntegerField(null=True)
    source_address_ids = models.TextField(null=True)
    local_destination_address_ids = models.TextField(null=True)
    domain_id = models.IntegerField(null=True)

    objects = UserManager()
    class Meta:
        db_table = "Offenses"

    def __set__(self):
        return self.Offenses

class Offense_category(models.Model):
    Oid = models.ForeignKey(Offenses, on_delete=models.CASCADE)

    class Meta:
        db_table = "Offense_category"

    def __set__(self):
        return self.Offense_category

移民

 class Migration(migrations.Migration):

    dependencies = [
        ('offense', '0008_auto_20190718_1107'),
    ]

    operations = [
        migrations.AlterField(
            model_name='offense_category',
            name='Oid',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='offense.Offenses'),
        ),
    ]

0 个答案:

没有答案