2016-05-27 4 views
2

Die model.py sieht wie folgt zu verstehen:Alembic Herabstufung scheint nicht die Meta-Daten

import datetime 

from sqlalchemy.ext.declarative import declarative_base 
from sqlalchemy import Column, Integer, String, Numeric, ForeignKey, DateTime, Boolean 
from sqlalchemy import create_engine 
from sqlalchemy.orm import sessionmaker, relationship 

from configs import config_base as config 
Base = declarative_base() 


class User(Base): 
    __tablename__ = 'user' 

    id = Column(String, unique=True, primary_key=True) 
    name = Column(String(100), nullable=False) 
    team_id = Column(String, ForeignKey('team.id')) 
    last_modified_on = Column(DateTime, default=datetime.datetime.utcnow()) 
    team = relationship('Team', back_populates='members') 


class Team(Base): 
    __tablename__ = 'team' 

    id = Column(String, unique=True, primary_key=True) 
    name = Column(String, nullable=False) 
    bot_access_token = Column(String(100), nullable=False) 
    bot_user_id = Column(String(100), nullable=False) 
    last_modified_on = Column(DateTime, default=datetime.datetime.utcnow()) 
    is_active = Column(Boolean, default=True) 
    members = relationship('User', back_populates='team') 
    is_first_time_news = Column(Boolean, default=True) 

engine = create_engine(config.SQLALCHEMY_DATABASE_URI) 
Base.metadata.create_all(engine) 
Session = sessionmaker(bind=engine) 

I is_first_time_news über diese alembic Migration gerade hinzugefügt:

revision = '6f9e2d360276' 
down_revision = None 
branch_labels = None 
depends_on = None 

from alembic import op 
import sqlalchemy as sa 


def upgrade(): 
    op.add_column('team', sa.Column('is_first_time_news', sa.Boolean, default=False)) 


def downgrade(): 
    op.drop_column('team', sa.Column('is_first_time_news', sa.Boolean)) 

alembic upgrade head funktioniert super .

Aber wenn ich eine alembic downgrade -1 bekomme ich eine seltsame Ausnahme:

AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute '_columns'

Antwort

0

Sie SQLite verwenden? Sqlite erlaubt es Ihnen nicht, eine Spalte aus dem Schema zu löschen. Ich hatte ein ähnliches Problem, als ich versuchte, eine lokale SQLite-Datenbank downzugraden, die ich gerade getestet hatte.

SQLite supports a limited subset of ALTER TABLE. The ALTER TABLE command in SQLite allows the user to rename a table or to add a new column to an existing table.

https://www.sqlite.org/lang_altertable.html

+0

Nein, sein postgres tatsächlich. – Houman