请教一下,flask_migrate创建的仓库文件夹为什么会在桌面?

db init之后,为什么会在桌面创建仓库?
程序所在目录不是桌面。
一直不明白·,还望大神不吝赐教,能给小弟指点一二。

阅读 2.2k
1 个回答

创建仓库的路径可以在config.py文件里进行设置。

# -*- coding:utf-8 -*-
__blog__ = u'http://www.os373.cn'
__author__ = u'东方鹗'

import os
import hashlib

basedir = os.path.abspath(os.path.dirname(__file__))


class Config(object):
    SECRET_KEY = os.environ.get('SECRET_KEY') or hashlib.new(name='md5', string='sdfasdfasdf').hexdigest()
    SQLALCHEMY_TRACK_MODIFICATIONS = True
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True


    @staticmethod
    def init_app(app):
        pass


class DevelopmentConfig(Config):
    DEBUG = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or \
                            'sqlite:///' + os.path.join(basedir, 'data_dev.sqlite')


class TestingConfig(Config):
    TESTING = True
    SQLALCHEMY_DATABASE_URI = os.environ.get('TEST_DATABASE_URL') or \
                            'sqlite:///' + os.path.join(basedir, 'data-test.sqlite')


class ProductionConfig(Config):
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
                            'sqlite:///' + os.path.join(basedir, 'data.sqlite')


config = {
    'development': DevelopmentConfig,
    'testing': TestingConfig,
    'production': ProductionConfig,
    'default': DevelopmentConfig
}

其中的SQLALCHEMY_DATABASE_URISQLALCHEMY_DATABASE_URI是要保存的sqlite数据库文件的路径。

而 flask_migrate 插件中,migrations文件夹的位置,就被设置在了config.py文件的同一文件夹下。

如果你是按照http://www.pythondoc.com/flas...教程做的,那么你可以查看migrate.py的源代码,查找仓库的文件设置路径。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题