Comments (7)
It's hard for me to know exactly how you caused this. But normally on a deployed version of the application you will run flask db upgrade
, never init
or migrate
. It seems to me you have not followed the deployment instructions from the tutorial, this is all covered there.
from microblog.
Yes, I have not followed the tutorial instructions. Acutally I tried to use both ways for deployment, one for Docker, one for hosting webiste. flask db upgrade
will cause the following error:
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade dc96d9b0d0bf -> e949960c17e9, let user be able to follow and unfollow
Traceback (most recent call last):
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context
self.dialect.do_execute(
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
cursor.execute(statement, parameters)
sqlite3.OperationalError: table user already exists
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/JTPing/microblog/venv/bin/flask", line 8, in <module>
sys.exit(main())
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/flask/cli.py", line 1047, in main
cli.main()
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/flask/cli.py", line 357, in decorator
return __ctx.invoke(f, *args, **kwargs)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/flask_migrate/cli.py", line 149, in upgrade
_upgrade(directory, revision, sql, tag, x_arg)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/flask_migrate/__init__.py", line 111, in wrapped
f(*args, **kwargs)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/flask_migrate/__init__.py", line 200, in upgrade
command.upgrade(config, revision, sql=sql, tag=tag)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/command.py", line 322, in upgrade
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/script/base.py", line 569, in run_env
util.load_python_file(self.dir, "env.py")
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 94, in load_python_file
module = load_module_py(module_id, path)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/util/pyfiles.py", line 110, in load_module_py
spec.loader.exec_module(module) # type: ignore
File "<frozen importlib._bootstrap_external>", line 883, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/home/JTPing/microblog/migrations/env.py", line 97, in <module>
run_migrations_online()
File "/home/JTPing/microblog/migrations/env.py", line 91, in run_migrations_online
context.run_migrations()
File "<string>", line 8, in run_migrations
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/runtime/environment.py", line 853, in run_migrations
self.get_context().run_migrations(**kw)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/runtime/migration.py", line 623, in run_migrations
step.migration_fn(**kw)
File "/home/JTPing/microblog/migrations/versions/e949960c17e9_let_user_be_able_to_follow_and_unfollow.py", line 21, in upgrade
op.create_table('user',
File "<string>", line 8, in create_table
File "<string>", line 3, in create_table
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/operations/ops.py", line 1254, in create_table
return operations.invoke(op)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/operations/base.py", line 399, in invoke
return fn(self, operation)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/operations/toimpl.py", line 114, in create_table
operations.impl.create_table(table)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/ddl/impl.py", line 354, in create_table
self._exec(schema.CreateTable(table))
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/alembic/ddl/impl.py", line 195, in _exec
return conn.execute(construct, multiparams)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1380, in execute
return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/sql/ddl.py", line 80, in _execute_on_connection
return connection._execute_ddl(
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1472, in _execute_ddl
ret = self._execute_context(
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1943, in _execute_context
self._handle_dbapi_exception(
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2124, in _handle_dbapi_exception
util.raise_(
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 210, in raise_
raise exception
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context
self.dialect.do_execute(
File "/home/JTPing/microblog/venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) table user already exists
[SQL:
CREATE TABLE user (
id INTEGER NOT NULL,
username VARCHAR(64),
email VARCHAR(120),
password_hash VARCHAR(128),
about_me VARCHAR(140),
last_seen DATETIME,
PRIMARY KEY (id)
)
]
The such above error said table user already exists
from microblog.
This is a result of the actions that you have taken, which put your database in a state that is out of sync with your code. The tutorial shows how to work with migrations, if you are going to deviate from that you have to have a good reason, because in most cases there is no need to do anything different.
You have two options now. Either you start over from scratch, or you make changes to your database so that it matches the code. Because now you have a database that has a table named user
, and you also have a new database migration that creates a table of the same name. That makes no sense and would never have happened if you followed the correct sequence.
from microblog.
Sorry, now I have to save it. If I do not want to start from scratch, then what can I make changes to database? Delete all data like user
table to match code? Actually, I found that register is also not working
I don't know why deviating from tutorial will cause sync is out of control.
from microblog.
I'm not really sure what changes you need to make, because I don't know what operations did you do that put you in the current state.
What I was trying to say that it does not make sense to have a database that has a user
table, and at the same time you have a migration that needs to be applied that creates a table with that same name. Something that you did created this inconsistency, so what you need to do is undo that. You can edit your database manually, deleting the user table and any other thing that shouldn't be there. This is going to be difficult to do if you don't fully understand what you have done, for that reason I suggest deleting the entire database and starting from scratch might make more sense for you.
from microblog.
I deleted app.db
but it still fail to work.
from microblog.
I did not indicate that deleting the database was the fix. What I suggested was to start over, which means you have to follow the instructions from the tutorial, exactly as given.
from microblog.
Related Issues (20)
- Issue with deployment on Heroko (Greenlet package) HOT 2
- How to solve the syntax conflict between JinJia2 and CSS in chapter 21.3 ? HOT 6
- Did you check documentation? HOT 2
- AttributeError: 'Babel' object has no attribute 'localeselector' HOT 2
- hi HOT 2
- 2023 update
- Popover does not work in chapter 20 due to bootstrapcdn source issue? HOT 5
- Member redis is unknown HOT 2
- Chapter 14 Translations fail unless the destination language is explicitly specified
- Chapter 22 Export task stuck at 0% HOT 5
- elastic_transport.ConnectionError when post is submitted? HOT 6
- Language inconsistency during poedit translation process? HOT 7
- Using JinJa2 filter function truncate to implement 'Read more'? HOT 21
- Bug in lesson 5 due to werkzeug.urls - url parsing removed HOT 4
- Lesson 6, FLASK_ENV is removed from Flask 2.3.0 HOT 2
- Unable to load celery application. 'str' object has no attribute 'level' when Integrating Celery with Flask? HOT 17
- Unable to import 'url_parse' from 'werkzeug.urls' in flask shell execution HOT 15
- Github links in chapters start with wrong tag (one-off) HOT 2
- Dead link to flask-babel docs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microblog.