Django的AWS弹性魔豆迁移数据库 [英] Django AWS Elastic Beanstalk migrate database

查看:229
本文介绍了Django的AWS弹性魔豆迁移数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我部署使用弹性魔豆一个Django项目,AWS和我被困在迁移的数据库。

I'm deploying a Django project to AWS using Elastic Beanstalk and am stuck on migrating the database.

我在哪里:我能够成功部署我的Django项目,并通过mysubdomain.elasticbeanstalk.com加载页面。该页面加载没有错误,直到我得到一个网页,需要做一个数据库调用。然后,我得到这样一个错误的关系accounts_user不存在线路1:SELECT COUNT(*)FROMaccounts_user,因为我的数据库没有被迁移。

Where I'm at: I am able to successfully deploy my django project and load the page through mysubdomain.elasticbeanstalk.com. The page loads without error until I get to a page that needs to do a database call. I then get an error like relation "accounts_user" does not exist LINE 1: SELECT COUNT(*) FROM "accounts_user" because my database hasn't been migrated.

我已经试过:我试过的东西相当多的变化。幸运的是计算器的帖子和几个教程丰盈。不幸的是,他们似乎都使用的是不同的版本,他们认为什么都不适用于我的项目。

What I've tried: I've tried quite a few variations of things. Fortunately there are an abundance of stackoverflow posts and a couple tutorials. Unfortunately, they all seem to be using a different version and what they suggest do not apply to my project.

这是pretty的清楚,我认为我需要运行在一个 foobar.config 文件中的 .ebextensions / <迁移/ code>文件夹。下面是我想要做的基础:

It is pretty clear to me that I need to run the migration in a foobar.config file inside the .ebextensions/ folder. Here is the base of what I want to do:

container_commands:
  01_migrate:
    command: "python manage.py migrate --noinput"
    leader_only: true

在日志中,我看到后部署脚本试图逃跑,但是失败了。我没有收到关于错误的任何其他信息,我唯一看到的是一样的东西ERROR:01_migrate部署后脚本失败

In the logs, I see that the post deployment script tried to run but it failed. I don't receive any other info on the error, the only thing I see is something like "ERROR: 01_migrate post deployment script failed"

我发现我需要激活的命令,这是有道理的虚拟环境。从航空自卫队我试试这个:

I find out that I need to activate the virtual environment for the command, which makes sense. From asdf I try this:

container_commands:
  01_migrate:
    command: "source /opt/python/run/venv/bin/activate && python rlg/manage.py migrate --noinput"
    leader_only: true

不过,这是行不通的。事实上,通过SSH我发现我甚至没有一个的/ opt /蟒蛇/文件夹,只/选择/ AWS /和/ opt / elasticbeanstalk /。所有教程和SO问题,将此文件夹,但我没有呢?

But it doesn't work. In fact, through SSH I find out I don't even have a /opt/python/ folder, only /opt/aws/ and /opt/elasticbeanstalk/. All tutorials and SO questions refer to this folder but I don't have it?

版本: Python的3​​.4.1,Django的1.7.7,AWS CLI 3.2.1,Postgres的9.3

VERSIONS: Python 3.4.1, Django 1.7.7, AWS CLI 3.2.1, Postgres 9.3

推荐答案

在container_commands都没有在泊坞窗容器中执行。他们在EC2实例直接执行。 目前我使用泊坞窗EXEC 来进行迁移。由于担心泊坞窗容器AFAIK最后一个开始我用泊坞窗PS -a --no-TRUNC -q |头-N 1 来获取容器的id。

The container_commands are NOT executed within the docker container. They are executed on the ec2 instance directly. Currently I'm using docker exec to do the migration. As the concerned docker container is afaik the last one started I use docker ps -a --no-trunc -q | head -n 1 to get the container id.

在结束我的setup.config看起来像

In the end my setup.config looks like that

container_commands:
  01syncdb:
    command: "docker exec `docker ps -a --no-trunc -q | head -n 1` /var/app/bin/python /var/app/manage.py syncdb --noinput  &>> /tmp/deploy.log"
    leader_only: true
  02migrate:
    command: "docker exec `docker ps -a --no-trunc -q | head -n 1` /var/app/bin/python /var/app/manage.py migrate --noinput  &>> /tmp/deploy.log"
    leader_only: true

我希望解决您的问题,以及。

I hope that solves your problem as well.

这篇关于Django的AWS弹性魔豆迁移数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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