如何切换到新数据库 [英] how to switch to a new database

查看:126
本文介绍了如何切换到新数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将django项目部署到生产环境中,并将其与新的空数据库关联,我做了如下操作:

I want to deploy my django project to the production environments, and associated it with an new empty database, and I did as follows :


  1. 创建一个新的空数据库

  2. 更新了settings.py,并将数据库名称指向了新数据库

  3. 删除了我的应用程序下的迁移文件夹

  4. 运行python manage.py runserver并且没有返回错误

  5. 运行python manage.py makemigrations和python manage.py migration

  1. Create an new empty database
  2. Updated settings.py and pointed the database name to the new one
  3. Deleted the migrations folder under my App
  4. Run python manage.py runserver and no errors returned
  5. Run python manage.py makemigrations and python manage.py migrate

,但仅创建与auth相关的表(例如 auth_user auth_group ...),没有为我的Apps创建数据库表

but only auth related tables created ( like auth_user , auth_group ... ), no databases tables created for my Apps

在这种情况下,我该如何做才能将其移动到项目的新数据库中?

How should I do for this situation to move to the new database for my project?

推荐答案



  1. 删除了我的应用程序下的迁移文件夹


这是您的错误,您删除了迁移-包括ini迁移。因此,当您转到 makemigrations 时,您没有初始迁移可用。

This was your mistake, you deleted the migrations - including the initial migrations. So when you go to makemigrations you haven't got the initial migration available.

因此您需要运行 makemigrations< app_name> 至少可以获得初始迁移。

So you need to run makemigrations <app_name> to at least get the initial migration.

如果您要再次执行此操作,请不要t删除迁移,只需更改数据库设置,然后迁移。

If you were to do this again, don't delete the migrations, just change the database settings and then migrate.

这篇关于如何切换到新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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