can you provide SQLAlchemy statement output please, set "level = INFO" under [logger_sqlalchemy] in alembic.ini
op.alter_column() does not emit DELETE and nothing in Alembic emits the DELETE statement anywhere except upon the alembic_version table itself. On Mon, Oct 8, 2018 at 10:31 AM Richard <goo...@richard.do> wrote: > > I'm using postgres version 10, alembic 1.0.0, sqlalchemy 1.2.12. I'm aware > ALTER COLUMN in SQL doesn't delete rows, but op.alter_column is doing that. > > My customer & daily reading models look like: > > > class Customer(DeclarativeBase): > __tablename__ = 'customers' > id = Column(Integer, primary_key=True) > electricity_readings = relationship( > 'ElectricityMeterReading', cascade='all,delete-orphan', > backref=backref('customer', cascade='all') > ) > gas_readings = relationship( > 'GasMeterReading', cascade='all,delete-orphan', > backref=backref('customer', cascade='all') > ) > daily_smart_meter_readings = relationship( > 'DailyMeterReading', > cascade='all,delete-orphan', > backref=backref('customer', cascade='all') > ) > > class DailyMeterReading(DeclarativeBase): > __tablename__ = 'daily_smart_meter_readings' > id = Column(Integer, primary_key=True) > customer_pk = Column( > Integer, ForeignKey('customers.id'), nullable=False, index=True > ) > reading = Column(Float, nullable=False) > reading_at = Column(UtcDateTime, nullable=False, index=True) > > > > > > > > On Monday, October 8, 2018 at 3:26:11 PM UTC+1, Mike Bayer wrote: >> >> Hi there - >> >> I have no idea what you are seeing. an actual ALTER COLUMN >> operation does not delete rows. Of course, if you are using SQLite >> and batch mode, that might affect things, but you have not specified >> this. Please specify complete information including log output, >> stack traces, database in use, sample schema, etc. >> >> On Mon, Oct 8, 2018 at 9:36 AM Richard <goo...@richard.do> wrote: >> > >> > >> > Note that if I do the same op.alter_column on another table which has a >> > customer FK, it works fine and does not delete all the rows. >> > >> > On Monday, October 8, 2018 at 1:50:38 PM UTC+1, Richard wrote: >> >> >> >> I have an alembic migration which renames a FK column on a table from >> >> 'customer_id' to 'customer_pk'. >> >> >> >> I used to have more in the migration file but narrowed it down to this >> >> code causing all the rows to be deleted. >> >> >> >> def upgrade(): >> >> op.alter_column( >> >> 'daily_smart_meter_readings', column_name='customer_id', >> >> new_column_name='customer_pk', >> >> ) >> >> >> >> >> >> I'm using alembic==1.0.0 and Python 3.6.4. >> >> >> >> Is there something wrong with the above code or is this a bug in the >> >> library? >> >> >> >> Thanks >> > >> > -- >> > You received this message because you are subscribed to the Google Groups >> > "sqlalchemy-alembic" group. >> > To unsubscribe from this group and stop receiving emails from it, send an >> > email to sqlalchemy-alembic+unsubscr...@googlegroups.com. >> > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy-alembic" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sqlalchemy-alembic+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sqlalchemy-alembic" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy-alembic+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.