Tag Archives: International server error

500 (International server error) server error in Flash + heroku

Recently I studied flask. I implemented it step by step in the book ** flasky: flask-web development: a practical approach to web application development based on Python **, which was flasky project on github. If you encounter one or two big problems, record them *
flask + heroku +postagres
1. Question 1:
After the success of heroku server git, the initial and updated database is similar to the following error:

heroku run python manager.py deploy # Initializing and updating the database

Running python manager.py deploy on ⬢ flasky-blog-mirui... ⣾ 
Running python manager.py deploy on ⬢ flasky-blog-mirui... ⣷ starting, run.7767 (Free)
Running python manager.py deploy on ⬢ flasky-blog-mirui... up, run.7767 (Free)

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> 8d6dba4cf1a4, the second migration

psycopg2.errors.UndefinedTable: relation "users" does not exist

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "users" does not exist

It is above error roughly, see the following error concretely one

    1. at the beginning, I read the error message, thinking that my

psycopg2

    1. was wrong (I installed binary package

psycopg2-binary

    1. , because I could not install

psycopg2

    1. ), I thought that there was something wrong with the database structure. Later, I optimized the data structure and type, and still reported an error. Execute

git push heroku master

    1. , it can be run. Open the link of

APP

    1. . As long as the page is dynamically connected to the database, it will be

500Internal Server Error

    1. to report Server Error. Apparently error connecting to the database to perform the

heroku logs - t </ code> found will report similar sqlalchemy. Exc. ProgrammingError: (psycopg2. Errors. UndefinedTable) base "posts" does not exist </ code> wrong, as wrong as before. The local postagres library is also used, and everything is fine. Eliminate database errors, code problems. But ~ ~, remember that I searched stackoverflow for Internal Server Error+flask+heroku and then I saw someone said to delete migrations 1 folder. git and initialization, there is no error, ztyd magic!
Solutions:
After making sure that the code is ok and running in the local virtual environment normally, the following actions can be taken:

Delete the annoying database version control migrations folder

rm -rf ,/migrations
git add .
git commit -am 'It will be fine'
git push heroku master
heroku run python manage,py deploy

Okay, so you can open up your heroku app.
Welcome to my heroku app flasky-blog-mirui, remember to leave me a message ~ ~ ~
* a wrong

heroku run python manager.py deploy # Initializing and updating the database
Running python manager.py deploy on ⬢ flasky-blog-mirui... ⣾ 
Running python manager.py deploy on ⬢ flasky-blog-mirui... ⣷ starting, run.7767 (Free)
Running python manager.py deploy on ⬢ flasky-blog-mirui... up, run.7767 (Free)

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> 8d6dba4cf1a4, the second migration
Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1244, in _execute_context
    cursor, statement, parameters, context
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 552, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.UndefinedTable: relation "users" does not exist


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manager.py", line 83, in <module>
    manager.run()
  File "/app/.heroku/python/lib/python3.6/site-packages/flask_script/__init__.py", line 417, in run
    result = self.handle(argv[0], argv[1:])
  File "/app/.heroku/python/lib/python3.6/site-packages/flask_script/__init__.py", line 386, in handle
    res = handle(*args, **config)
  File "/app/.heroku/python/lib/python3.6/site-packages/flask_script/commands.py", line 216, in __call__
    return self.run(*args, **kwargs)
  File "manager.py", line 67, in deploy
    upgrade()
  File "/app/.heroku/python/lib/python3.6/site-packages/flask_migrate/__init__.py", line 95, in wrapped
    f(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/flask_migrate/__init__.py", line 280, in upgrade
    command.upgrade(config, revision, sql=sql, tag=tag)
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/command.py", line 276, in upgrade
    script.run_env()
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/script/base.py", line 475, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/util/pyfiles.py", line 90, in load_python_file
    module = load_module_py(module_id, path)
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/util/compat.py", line 177, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "migrations/env.py", line 96, in <module>
    run_migrations_online()
  File "migrations/env.py", line 90, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/runtime/environment.py", line 839, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/runtime/migration.py", line 362, in run_migrations
    step.migration_fn(**kw)
  File "/app/migrations/versions/8d6dba4cf1a4_the_second_migration.py", line 21, in upgrade
    op.add_column('users', sa.Column('confirmed', sa.Boolean(), nullable=True))
  File "<string>", line 8, in add_column
  File "<string>", line 3, in add_column
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/operations/ops.py", line 1904, in add_column
    return operations.invoke(op)
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/operations/base.py", line 345, in invoke
    return fn(self, operation)
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/operations/toimpl.py", line 131, in add_column
    operations.impl.add_column(table_name, column, schema=schema)
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/ddl/impl.py", line 231, in add_column
    self._exec(base.AddColumn(table_name, column, schema=schema))
  File "/app/.heroku/python/lib/python3.6/site-packages/alembic/ddl/impl.py", line 134, in _exec
    return conn.execute(construct, *multiparams, **params)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 988, in execute
    return meth(self, multiparams, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/sql/ddl.py", line 72, in _execute_on_connection
    return connection._execute_ddl(self, multiparams, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1050, in _execute_ddl
    compiled,
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context
    e, statement, parameters, cursor, context
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1466, in _handle_dbapi_exception
    util.raise_from_cause(sqlalchemy_exception, exc_info)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/util/compat.py", line 152, in reraise
    raise value.with_traceback(tb)
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 1244, in _execute_context
    cursor, statement, parameters, context
  File "/app/.heroku/python/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 552, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedTable) relation "users" does not exist