Please edit configuration/connection/logging settings in '/home/mac126/Desktop/13/test3-1/migr

Posted liangliangzz

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Please edit configuration/connection/logging settings in '/home/mac126/Desktop/13/test3-1/migr相关的知识,希望对你有一定的参考价值。

flask迁移生成两个表,初始化

python manage.py db init

  结果出来的就是

Creating directory /home/mac126/Desktop/13/test3-1/migrations ... done
  Creating directory /home/mac126/Desktop/13/test3-1/migrations/versions ... done
  Generating /home/mac126/Desktop/13/test3-1/migrations/env.py ... done
  Generating /home/mac126/Desktop/13/test3-1/migrations/README ... done
  Generating /home/mac126/Desktop/13/test3-1/migrations/alembic.ini ... done
  Generating /home/mac126/Desktop/13/test3-1/migrations/script.py.mako ... done
  Please edit configuration/connection/logging settings in
  /home/mac126/Desktop/13/test3-1/migrations/alembic.ini before proceeding.

本以为是个错误,其实这个只要你初始化python manage.py db init就会出现这个,这个不是错误。既然不是错误为什么创建的两个表没有成功呢,运行也可以的,就是没有表,继续看

进行python manage.py db migrate迁移
INFO  [alembic.runtime.migration] Context impl mysqlImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.env] No changes in schema detected.

no changes in schema detected自然不会生成新表,百度了一下,方案很多木有解决,抱着尝试的态度,最终解决了,废话不多说,看源码:

#创建manage.py文件
from flask_migrate import MigrateCommand
from flask_script import Manager

from app import create_app

app = create_app(developConfig)

manage=Manager(app)

manage.add_command(db,MigrateCommand)
#迁移的时候一定要加,不加报错manage.py: error: invalid choice: ‘db‘ (choose from ‘shell‘, ‘runserver‘)

if __name__ == __main__:
    manage.run()


# 如果想要使用session ,必须要给定一个SECRET_KEY
# 因为flask没有对session进行处理,所以,我们需要自己去处理session,也就是将session进行持久化  ,默认存储在系统的内存中
# 那么我们要将它放到制定的地方  redis
# 需要一个配置信息   SESSION_TYPE = ‘redis‘
# Session(app)

# ‘mysql+pymysql://root:[email protected]:3306/database‘

# 使用flask-sqlalchemy   需要两个配置信息
# SQLALCHEMY_DATABASE_URI
# 自己去看警告信息

# ext.py   里面主要放第三方扩展包的初始化信息
# settings.py  所有的配置信息  ,配置文件

# db.createall()
# db.drop_all()

# db.session.add(对象)
# db.session.commit()


# 数据库的事务:
# 原子性:不可再分    一致性:保持一致   隔离性:不能受到外界影响   持久性:做长久保存
# http://www.cnblogs.com/fjdingsd/p/5273008.html
#创建__init__.py文件
from flask import Flask

from app import settings
from app.ext import init_ext
from app.views import blue


def create_app(envir):
    app = Flask(__name__)
    app.register_blueprint(blueprint=blue)
    app.config.from_object(settings.config_info.get(envir))
    init_ext(app)  # 没有这个会报KeyError: ‘migrate‘

    return app
#创建settings.py文件
# 关于咱们的四个生产环境
# 开发环境    测试环境   演示环境   线上环境
#针对MySQL的数据库配置,可以调用没有写死
def get_database_url(info):
    name = info.get(name) or mysql
    username = info.get(username) or root
    password = info.get(password) or 123456
    host = info.get(host) or localhost
    port = info.get(port) or 3306
    driver = info.get(driver) or pymysql
    database = info.get(database) or num1

    return {}+{}://{}:{}@{}:{}/{}.format(name,driver,username,password,host,port,database)

#配置信息类也可以说是线上环境
class Config():
    DEBUG = False#默认调试模式关闭
    TESTING = False#测试模式关闭
    SECRET_KEY = 123#密钥
    SESSION_TYPE = redis#session存储类型
    SQLALCHEMY_TRACK_MODIFICATIONS = False#报的一个提示不是错,只是一个警告信息,通过这个可以关闭提示,想了解可以注释掉自己看看



#开发环境
class DevelopConfig(Config):

    DEBUG = True
    TESTING = True

    database = {
        username: root,
        password: 123456,
        host: localhost,
        port: 3306,
        database: num1,
        driver:pymysql,
        name : mysql
    }

    # 链接数据库的url
    SQLALCHEMY_DATABASE_URI = get_database_url(database)

#测试环境
class TestConfig(Config):
    TESTING = True

    database = {
         username: root,
        password: 123456,
        host: localhost,
        port: 3306,
        database: num1,
        driver:pymysql,
        name : mysql
    }

    SQLALCHEMY_DATABASE_URI = get_database_url(database)

#演示环境
class ShowConfig(Config):

    database = {
        username: root,
        password: 123456,
        host: localhost,
        port: 3306,
        database: num1,
        driver: pymysql,
        name: mysql
    }

    SQLALCHEMY_DATABASE_URI = get_database_url(database)

#生产环境
class WorkConfig(Config):

    database = {
         username: root,
        password: 123456,
        host: localhost,
        port: 3306,
        database: num1,
        driver:pymysql,
        name : mysql
    }

    SQLALCHEMY_DATABASE_URI = get_database_url(database)


#封装四个开发环境
config_info = {

    "WorkConfig": WorkConfig,
    "developConfig":DevelopConfig,
    "testConfig": TestConfig,
    "showConfig": ShowConfig,
    "default": DevelopConfig,
}
#创建ext.py文件
from flask_migrate import Migrate
from flask_session import Session
from flask_sqlalchemy import SQLAlchemy


db = SQLAlchemy()

migrate=Migrate(db=db)



def init_ext(app):
    db.init_app(app)
    migrate.init_app(app)

    sess=Session()

    sess.init_app(app)
#创建views.py文件
from flask import Blueprint

blue=Blueprint(first,__name__)


@blue.route(/)
def hello_world():
    return Hello World!
#创建modles.py文件
from app.ext import db


class User(db.Model):
    u_id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    u_name = db.Column(db.String(32))
    u_age = db.Column(db.Integer)


class Person(db.Model):
    p_id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    p_name = db.Column(db.String(32))
    p_age = db.Column(db.Integer)
    goods = db.relationship(Goods,backref=person)

检查运行没有错误,表就是不生成。我在views.py文件里面添加了增减用户函数,问题神奇的解决了

views.py文件

from flask import Blueprint

from app.ext import db
from app.modles import User

blue=Blueprint(first,__name__)

@blue.route(/)
def hello_world():
    return Hello World!
@blue.route(/adduser/)
def add_user():
    # 添加单个数据
    user = User()

    user.u_name = 老贾
    user.u_age = 18

    db.session.add(user)
    db.session.commit()

    return 数据添加成功

 

以上是关于Please edit configuration/connection/logging settings in '/home/mac126/Desktop/13/test3-1/migr的主要内容,如果未能解决你的问题,请参考以下文章

IDEA please configure web facet first

configure: error: mysql configure failed. Please check config.log for more information.

configure: error: Please reinstall the libcurl distribution

Error: Please renew the default configurations.

解决 PHP Interpreter is not configured Please configure PHP Interpreter to use built-in web server(示例代

IntelliJ IDEA 2017 提示“Unmapped Spring configuration files found.Please configure Spring facet.”