无法从SQLite切换到Postgres

时间:2016-11-30 08:20:02

标签: postgresql flask flask-sqlalchemy

我一直在关注Postgres的本教程中的所有内容:https://realpython.com/blog/python/flask-by-example-part-2-postgres-sqlalchemy-and-alembic/

我一直收到以下错误。我不明白为什么当我专门设置使用Postgres的所有内容时,我的系统继续选择使用SQLite。

    (table.description, column.name, ce.args[0])
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 202, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 2329, in visit_create_table
    and not first_pk)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 242, in process
    return obj._compiler_dispatch(self, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 81, in _compiler_dispatch
    return meth(self, **kw)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 2360, in visit_create_column
    first_pk=first_pk
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/dialects/sqlite/base.py", line 865, in get_column_specification
    column.type, type_expression=column)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/compiler.py", line 290, in process
    return type_._compiler_dispatch(self, **kw)
  File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/visitors.py", line 79, in _compiler_dispatch
    raise exc.UnsupportedCompilationError(visitor, cls)
sqlalchemy.exc.CompileError: (in table 'results', column 'result_all'): Compiler <sqlalchemy.dialects.sqlite.base.SQLiteTypeCompiler object at 0x1110e4090> can't render element of type <class 'sqlalchemy.sql.sqltypes.JSON'>

这就是我对views.py

的看法
from flask import render_template
#from app import app
from flask import Flask
from flask import Flask, flash, redirect, render_template, request, session, abort
from flask_sqlalchemy import SQLAlchemy
import os


app = Flask(__name__)
app.config.from_pyfile('../config.py')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)

from models import Result

这是我的Config.py

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


class Config(object):
    DEBUG = False
    TESTING = False
    CSRF_ENABLED = True
    SECRET_KEY = 'this-really-needs-to-be-changed'
    SQLALCHEMY_DATABASE_URI = os.environ['DATABASE_URL']


class ProductionConfig(Config):
    DEBUG = False


class StagingConfig(Config):
    DEVELOPMENT = True
    DEBUG = True


class DevelopmentConfig(Config):
    DEVELOPMENT = True
    DEBUG = True


class TestingConfig(Config):
    TESTING = True

1 个答案:

答案 0 :(得分:1)

将postgres驱动程序添加到数据库uri

postgresql+psycopg2://user:password@host:port/dbname