烧瓶DB命令:Importerror

发布于 2025-02-03 22:43:00 字数 3406 浏览 4 评论 0原文

我是Flask和Python的新手(我有其他语言和前端开发人员的背景)。

当前试图使用其他列更新我的SQLite3数据库。我的应用程序正在为我抛出一个“未找到”错误。从这里开始,我了解了需要刷新SQLITE3数据库的需求。我发现烧瓶迁移和Alembic是这些解决方案的一部分,我需要使用烧瓶迁移以更新SQLITE3数据库。

我在/users/xxxx/code/platform/venv/lib/python3.8/site-packages文件夹中,

app tree treond

/Platform
|-__init__.py
|-models.py
|-platform.sqlite3
templates
    |--index.html
venv
|-bin
|-include
|-library
|-pyvenv.cfg
static
|-css
|-js
alembic
admin
|-_pycache_
|-static
|-templates
|__init.py__
|admin.py
__pycache__
requirements.txt
README.md

itre.py.py.py 文件:

from crypt import methods
from enum import unique
from flask import Flask, redirect, url_for, render_template, session, request
from datetime import datetime, timedelta, timezone
from sqlalchemy import over
from models import db, Users
from flask_wtf import FlaskForm
from flask_login import UserMixin, login_manager, login_user, LoginManager, login_required, logout_user, current_user
from flask_migrate import Migrate
from forms import UserForm, LoginForm, Survey
from werkzeug.security import generate_password_hash, check_password_hash

# Blueprints
from admin import admin

models.py/admin/

from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from datetime import datetime

db = SQLAlchemy()

< strong> init.py _文件:

from flask import Blueprint, request, redirect, session
from flask.templating import render_template
from models import db, Users
from forms import UserForm
from sqlalchemy import func, join
from flask_login import login_required, logout_user, current_user
from collections import namedtuple

我正在尝试在烧瓶应用程序中更新SQLITE3数据库。

我不断收到一个错误(“错误:导入'Platform.wsgi'时,提高了Importerror。”)尝试运行'flask db db迁移'刷新以刷新SQLite3数据库,因此添加的列将显示在我的应用中。

在进一步检查时,我尝试在Mac上的终端中使用'Flask db'运行不同的命令。

运行'烧伤db'向我显示命令列表:(分支,当前,降级,编辑,头部等)。

flask db
Usage: flask db [OPTIONS] COMMAND [ARGS]...

  Perform database migrations.

Options:
  --help  Show this message and exit.

Commands:
  branches        Show current branch points
  current         Display the current revision for each database.
  downgrade       Revert to a previous version
  edit            Edit a revision file
  heads           Show current available heads in the script directory
  history         List changeset scripts in chronological order.
  init            Creates a new migration repository.
  list-templates  List available templates.
  merge           Merge two revisions together, creating a new revision file
  migrate         Autogenerate a new revision file (Alias for 'revision...
  revision        Create a new revision file.
  show            Show the revision denoted by the given symbol.
  stamp           'stamp' the revision table with the given revision;...
  upgrade         Upgrade to a later version

问题是我任何时候尝试运行'烧瓶db init''烧伤db迁移'以更新我的sqlite3 db,我得到此错误:

“错误” :在导入“ platform.wsgi”时,提高了Importerror。”

我不确定如何解决继续显示的WSGI错误。似乎一旦解决这个问题,我将能够运行烧瓶DB迁移以更新我的数据库并获取新的数据和列以显示。

非常感谢有时间阅读此书并提供任何建议。在过去的四天中,我一直被困在此过程中,阅读和故障排除我在Stackoverflow上发现的所有各种想法,但没有运气。

这是我在这里的第一篇文章。

谢谢

I am new to flask and python (I have background in other languages and front-end dev).

Currently trying to update my sqlite3 database with additional columns. My app is throwing me a "no column found" error. From here, I have read about the need to refresh the sqlite3 database. I discovered that Flask Migrate and Alembic are part of these solutions and I need to use Flask Migrate to update the sqlite3 database.

I have Alembic and Flask Migrate in the /Users/xxxx/code/Platform/venv/lib/python3.8/site-packages folder

The app tree is

/Platform
|-__init__.py
|-models.py
|-platform.sqlite3
templates
    |--index.html
venv
|-bin
|-include
|-library
|-pyvenv.cfg
static
|-css
|-js
alembic
admin
|-_pycache_
|-static
|-templates
|__init.py__
|admin.py
__pycache__
requirements.txt
README.md

init.py file:

from crypt import methods
from enum import unique
from flask import Flask, redirect, url_for, render_template, session, request
from datetime import datetime, timedelta, timezone
from sqlalchemy import over
from models import db, Users
from flask_wtf import FlaskForm
from flask_login import UserMixin, login_manager, login_user, LoginManager, login_required, logout_user, current_user
from flask_migrate import Migrate
from forms import UserForm, LoginForm, Survey
from werkzeug.security import generate_password_hash, check_password_hash

# Blueprints
from admin import admin

models.py

from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from datetime import datetime

db = SQLAlchemy()

/admin/init.py_ file:

from flask import Blueprint, request, redirect, session
from flask.templating import render_template
from models import db, Users
from forms import UserForm
from sqlalchemy import func, join
from flask_login import login_required, logout_user, current_user
from collections import namedtuple

I am trying to update the sqlite3 database in my flask app.

I continuously get an error ("Error: While importing 'Platform.wsgi', an ImportError was raised.") when trying to run 'flask db migrate' to refresh the sqlite3 database so the added columns will show up in my app.

On further inspection, I have tried running different commands with 'flask db' in terminal on mac.

Running 'flask db' shows me a list of commands: (branches, current, downgrade, edit, heads, etc).

flask db
Usage: flask db [OPTIONS] COMMAND [ARGS]...

  Perform database migrations.

Options:
  --help  Show this message and exit.

Commands:
  branches        Show current branch points
  current         Display the current revision for each database.
  downgrade       Revert to a previous version
  edit            Edit a revision file
  heads           Show current available heads in the script directory
  history         List changeset scripts in chronological order.
  init            Creates a new migration repository.
  list-templates  List available templates.
  merge           Merge two revisions together, creating a new revision file
  migrate         Autogenerate a new revision file (Alias for 'revision...
  revision        Create a new revision file.
  show            Show the revision denoted by the given symbol.
  stamp           'stamp' the revision table with the given revision;...
  upgrade         Upgrade to a later version

The issue is anytime I try and run a 'flask db init' or 'flask db migrate' to update my sqlite3 db, I get this error:

"Error: While importing 'Platform.wsgi', an ImportError was raised."

I am not sure how to solve for this wsgi error that continues to show up. It seems once I solve for this, I will be able to run flask db migrate to update my database and get the new data and columns to show up.

Really appreciate the time to read this and offer any advice. I've been stuck on this for the past 4 days, reading and troubleshooting all the various ideas I have found here on StackOverflow, but no luck.

This is my first post here.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文