将Django与遗留数据库集成可以

2024-10-01 15:33:43 发布

您现在位置:Python中文网/ 问答频道 /正文

每个人:我正在尝试使用django1.8,mysql db来练习将Django与遗留数据库集成,但没有成功,有人能告诉我发生了什么吗??非常感谢你! 我的旧数据库

models.py

# -*- coding: utf-8 -*-
from django.db import models
from django.utils import timezone


class blog(models.Model):
    name = models.CharField(max_length=255)
    description = models.TextField()
    slug = models.SlugField(unique=True)
    date_time = models.DateTimeField(auto_now_add = True)

    def __unicode__(self):
        return self.name



def get_image_path(instance, filename):
    return '/'.join(['blog_images', instance.bupimg.slug, filename])

class Upload(models.Model):
    bupimg = models.ForeignKey(blog, related_name="uploads")
    image = models.ImageField(upload_to=get_image_path)

我就跟着doc here

在我输入命令后 enter image description here

为什么是我的pidapp/模型.py显示的内容与旧数据库的非常不同模型.py在

pidapp/models.py

^{pr2}$

我以为pidapp/模型.py应该与旧数据库的相同模型.py在


Tags: djangonamefrompy模型imageimport数据库
1条回答
网友
1楼 · 发布于 2024-10-01 15:33:43

你的所作所为毫无意义。你已经有了模型.py,为什么要创建一个新的?这里的“遗留数据库”指的是在Django之外创建的数据库,因此没有模型.py. 绝对没有理由在已经定义了模型的数据库上运行inspectdb。在

(另外,生成的模型是正确的;该文件包含数据库中所有现有表的模型,包括blogging表,但也包括所有其他Django表。同样,在这里运行inspectdb时,没有点。)

相关问题 更多 >

    热门问题