gpt4 book ai didi

postgresql - 无法从 SQLite 切换到 Postgres

转载 作者:行者123 更新时间:2023-11-29 13:21:26 25 4
gpt4 key购买 nike

我一直在关注本 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

最佳答案

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

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

关于postgresql - 无法从 SQLite 切换到 Postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40883395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com