相关疑难解决方法(0)

将models.py拆分为多个文件

我正在尝试将models.py我的应用程序拆分为几个文件:

我的第一个猜测是这样做:

myproject/
    settings.py
    manage.py
    urls.py
    __init__.py
    app1/
        views.py
        __init__.py
        models/
            __init__.py
            model1.py
            model2.py
    app2/
        views.py
        __init__.py
        models/
            __init__.py
            model3.py
            model4.py
Run Code Online (Sandbox Code Playgroud)

这不起作用,然后我找到了这个,但在这个解决方案中我仍然有一个问题,当我运行时,python manage.py sqlall app1我有类似的东西:

BEGIN;
CREATE TABLE "product_product" (
    "id" serial NOT NULL PRIMARY KEY,
    "store_id" integer NOT NULL
)
;
-- The following references should be added but depend on non-existent tables:
-- ALTER TABLE "product_product" ADD CONSTRAINT "store_id_refs_id_3e117eef" FOREIGN KEY     ("store_id") REFERENCES "store_store" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "product_product_store_id" ON …
Run Code Online (Sandbox Code Playgroud)

python django import django-models

77
推荐指数
4
解决办法
4万
查看次数

标签 统计

django ×1

django-models ×1

import ×1

python ×1