PostgreSQL。 Models.py不会转换成数据库方案 [英] PostgreSQL . Models.py is not transformed into database scheme

查看:137
本文介绍了PostgreSQL。 Models.py不会转换成数据库方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个问题。首先是由于Django使用应用程序名称前缀转换模型类名,并且只要该部分已解决'关系不存在'转移到PostgreSQL之后的错误我想这可能是正确的做出不同的问题。我收到如关系blog_userprofile不存在,并通过

There were two issues. First was due to Django converting model class name with app name prefix, and as far as that part was solved 'Relation does not exist' error after transferring to PostgreSQL I suppose it may be right to make different question.I was getting such errors as relation "blog_userprofile" does not exist and found out by

select column_name, data_type, character_maximum_length
from INFORMATION_SCHEMA.COLUMNS where table_name = 'closer';  

现有数据库中没有列 close ,所以 python manage.py migrate python manage.py make migration python manage .py make appname python manage.py syncdb 都基本上无法正常工作,没有将models.py转换成数据库方案。

that there are no columns in existing database closer, so python manage.py migrate , python manage.py make migrations , python manage.py make appname, python manage.py syncdb all basically didn't works properly and didn't transform models.py into database scheme.

为什么?我该如何解决?我尝试从models.py中删除所有的内容并再次运行所有的命令,但是它仍然在非现有字段(?)上输出错误,如 django.db.utils.ProgrammingError:relationblog_community已经存在code>。我试图使用 - 假的初始 flush 重置但是这两个都没有帮助。

Why? How do I solve this ? I'v tried deleting everything from models.py and running all commands again, but it still outputs errors on nonexisting fields (?) like django.db.utils.ProgrammingError: relation "blog_community" already exists . I tried to to use --fake initial and flush and reset but neither of those helped.

推荐答案

由于你从mysql转到postgresql,可以安全地假设你的postgresql数据库没有您需要的任何数据。

Since you are moving from mysql to postgresql, it's safe to assume that your postgresql db does not have any data that you need.

您当前的模型可能直接导入postgresql。但是,这并不意味着您所拥有的迁移文件与postgresql兼容。

Your current models can probably be imported directly into postgresql. However that does not mean the migration file that you have on file is compatible with postgresql.

很可能您的模型在一段时间内演变,很有可能有许多旧的迁移文件与postgresql不兼容。

It's very likely that your models evolved over a period of time and it's very likely that there are many old migrations files that are not compatible with postgresql.

步骤1:浏览项目中的所有应用程序,并清除迁移文件夹。

Step 1: Go through all the apps in your project and clear out the migrations folder.

步骤2:删除postgresql数据库(假设没有任何数据)

Step 2: drop the postgresql database (assuming it doesn't have any data)

步骤3:执行以下命令为django内部表创建迁移

Step 3: Do the following command to create migrations for django internal tables

 ./manage.py makemigrations

步骤4:为每个应用程序执行以下命令。

Step 4: Do the following command for each of your apps.

 ./manage.py makemigrations my_app_name

步骤4:最后,执行

 ./manage.py migrate.

这篇关于PostgreSQL。 Models.py不会转换成数据库方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆