alembic

Integrating Alembic with SQLAlchemy

与世无争的帅哥 提交于 2019-12-21 01:05:34
问题 I'm looking at a way to integrate Alembic with SQLAlchemy. What I need is a way so that Alembic detects any changes I make in models.py automatically and updates it in the MySQL database when I run alembic revision -m "<message_here>" and alembic upgrade head . Here is what I have at the moment. This is my application directory structure. /myapplication models.py __init__.py app.py /migrations env.py script.py.mako /versions The models.py contains the following. from sqlalchemy import Column,

Fetch table values using alembic and update to another table.

房东的猫 提交于 2019-12-20 17:36:37
问题 I have oauth secret and oauth key in client table. Now I moving them to oauth credentials table which will be created during migration. Alembic produced following schema for upgrade. from myapp.models import Client, ClientCredential from alembic import op import sqlalchemy as sa def upgrade(): ### commands auto generated by Alembic - please adjust! ### op.create_table('client_credential', sa.Column('id', sa.Integer(), nullable=False), sa.Column('created_at', sa.DateTime(), nullable=False), sa

Why did I have problems with alembic migrations

别等时光非礼了梦想. 提交于 2019-12-14 02:08:19
问题 Project structue(only directory with DB migrations): --db_manage: alembic.ini --alembic: env.py script.py.mako README --versions: #migration files When I try to run command: python db_manage/alembic/env.py , I have response like: Traceback (most recent call last): File "db_manage/alembic/env.py", line 8, in <module> config = context.config AttributeError: module 'alembic.context' has no attribute 'config' In which case I have that problem? P.S. File alembic.ini : # A generic, single database

Alembic/Flask-migrate doesn't recognise database structure

梦想与她 提交于 2019-12-13 20:53:22
问题 I have a Flask-based application and I'm trying to enable migrations to be able to manage database structural changes. My database is not empty and contains tables and records before I started with alembic and flask-migrate. First, I tried to use alembic stand-alone, just pip install alembic and then configure everything and use autogenerate for generating the diff. All works fine but the output was not exactly what I expected: INFO [alembic.autogenerate.compare] Detected removed table u'user

Add column after another column

我们两清 提交于 2019-12-12 10:47:10
问题 How can I add a column after another column to a database using Alembic or SQLAlchemy? That would be equivalent to this SQL clause: ALTER TABLE foo CHANGE COLUMN bar bar COLUMN_DEFINITION_HERE AFTER OTHER_COLUMN; -- or ALTER TABLE foo ADD COLUMN baz AFTER bar; I also tried the suggestion in this mailing list thread, but it didn't help. While the order doesn't matter when querying, it helps readability for large tables when in the SQL shell. 回答1: Use ALTER with AFTER to specify where to place

psycopg2.ProgrammingError: relation “event” does not exist

对着背影说爱祢 提交于 2019-12-12 01:17:36
问题 I am using alembic along with flask-migrate along with Postgres for my database. I have ran a db init and db migrate. However when i run the db upgrade command, I get the following error: cursor.execute(statement, parameters) psycopg2.ProgrammingError: relation "event" does not exist The above exception was the direct cause of the following exception: I am very well aware of why the error is happening. The script is trying to create the Attendee table which references an Event table that is

Alembic Migrations for Flask

梦想与她 提交于 2019-12-11 19:24:54
问题 I have been trying to get the Alembic migration system configured for my Flask app for the past 7 hours with no success. Any ideas as to what I am doing wrong? I have tried all the solutions I found here, but they did not seem to work for me. I get the following error after running the commands: $ heroku run alembic revision -m "please work" --autogenerate Running `alembic revision -m please work --autogenerate` attached to terminal... up, run.6050 Traceback (most recent call last): File "

alembic “failed to create process.” in Windows7

这一生的挚爱 提交于 2019-12-11 13:55:42
问题 I already installed python2.7, pip, env and alembic successfully, I try to run command "alembic init elembic" in command prompt but it not success, it show the message "failed to create process.". Anyone why and how to solve it? 回答1: You are probably seeing this as a result of a pip bug where it fails to correctly quote the python install path if it includes any spaces. You can work around it by either installing python to a path without any spaces or editing the first line of scripts

ERROR [alembic.env] name 'Text' is not defined upon 'python manage.py db upgrade'

余生长醉 提交于 2019-12-11 06:08:31
问题 Replicating this link to first test the feasibility of DB migration.. This turns out to be a bug in Alembic, and I tried adding from sqlalchemy.types import Text to no avail. This link is supposed to be a fix, but I cannot quite see which part of the code I can use for my purpose. from alembic import autogenerate from app import db import sqlalchemy as sa from sqlalchemy.dialects.postgresql import JSON from sqlalchemy import Integer, String, TIMESTAMP from sqlalchemy.types import Text class

Alembic trying to delete my tables

橙三吉。 提交于 2019-12-11 04:49:32
问题 Alembic beginner here. I'm having some issues with Alembic trying to delete my tables that are already created. I have no idea what is going on. Right now I have a database that looks like this: If I run alembic upgrade head , I get this as my result: INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL. If I run alembic history , I get this result, which is correct: c2659db918a9 -> 765c30f7078c (head), creat table views