V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
raiz
V2EX  ›  Heroku

求助: django 部署在 heroku , 数据库出问题, 想知道在 免费版的 heroku app 上 如何管理数据库

  •  1
     
  •   raiz · 2015-07-05 08:55:03 +08:00 · 5620 次点击
    这是一个创建于 3190 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1. 我开发环境是 python34 django 1.8.1
    2. 本地用数据库是 sqlite3, heroku 用到 postgres
    3. 我部署在heroku上是给另一个人测试用的,由于一直变更需求,表结构要变
    4. 我情景是,我之前的工程已经在 herok 上跑,没有问题, 然后我在 model中添加了一个 class Message(models.Model): user = models.ForeignKey('GameUser') 而 GameUser 是原来有的一个model
    5. 然后我push了,然后在heroku 上执行

    python manage.py makemigrations
    python manage.py migrate
    然后进入 python manage.py shell , 导入model后, 执行 Message.objects.all() ,提示上面的提问里错误

    Traceback (most recent call last):
    File "<console>", line 1, in <module>
    File "/app/.heroku/pythonb/python3.4/site-packages/django/models/query.py", line 138, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
    File "/app/.heroku/pythonb/python3.4/site-packages/django/models/query.py", line 162, in __iter__
    self._fetch_all()
    File "/app/.heroku/pythonb/python3.4/site-packages/django/models/query.py", line 965, in _fetch_all
    self._result_cache = list(self.iterator())
    File "/app/.heroku/pythonb/python3.4/site-packages/django/models/query.py", line 238, in iterator
    results = compiler.execute_sql()
    File "/app/.heroku/pythonb/python3.4/site-packages/django/modelsl/compiler.py", line 837, in execute_sql
    cursor.execute(sql, params)
    File "/app/.heroku/pythonb/python3.4/site-packages/django/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
    File "/app/.heroku/pythonb/python3.4/site-packages/django/utils.py", line 97, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
    File "/app/.heroku/pythonb/python3.4/site-packages/django/utils/six.py", line 658, in reraise
    raise value.with_traceback(tb)
    File "/app/.heroku/pythonb/python3.4/site-packages/django/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
    django.db.utils.ProgrammingError: relation "dbmanager_message" does not exist
    LINE 1: ..."msg_code", "dbmanager_message"."parameters" FROM "dbmanager...

    然而执行 GameUser.objects.all() 并不会报错
    4 条回复    2015-07-06 00:11:38 +08:00
    fuermosi777
        1
    fuermosi777  
       2015-07-05 11:30:10 +08:00
    可以直接psql连到heroku app的数据库里添表
    raiz
        2
    raiz  
    OP
       2015-07-05 12:51:28 +08:00
    @fuermosi777 谢谢指点 是指本地下载 psql , 然后远程连接到 heroku的数据库吗? 我的表里很多字段,是不是要写很多sql语句?
    fuermosi777
        3
    fuermosi777  
       2015-07-05 21:58:27 +08:00
    我以前用1.6的时候 是psql直接连heroku数据库 然后本地运行一下`python manage.py sqlall app`,自动生成添加字段或者表的sql语句,然后复制到psql里运行一下就好了。好像自从Django1.8以后添加了migration功能。但由于模型不是经常修改,所以直接修改的方法并不是很麻烦。
    raiz
        4
    raiz  
    OP
       2015-07-06 00:11:38 +08:00
    @fuermosi777 最后采用了 本地使用 postgres, pg_dump 为 txt文件, 然使用 heroku 的pg:backup restore 为远程数据库
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2858 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:31 · PVG 19:31 · LAX 04:31 · JFK 07:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.