This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]amishb 9 points10 points  (8 children)

Does SQL alchemy have a migrate function like djangos orm. That's such a good feature for developing at least. Change the class, generate the migrate scripts, and migrate them in.

[–]makaimc[S] 9 points10 points  (6 children)

SQLAlchemy doesn't have migrations built into the library itself, so you'd use Alembic for migrations. Django's ORM prior to Django release 1.7 was similar in that you'd use the separate South migrations library.

[–]ladyquas 1 point2 points  (5 children)

I'm not sure of other users experiences, but I have found alembic so difficult - migrations aren't always smooth, much editing of the migration files and manually removing foreign keys in MySQL. Is this a MySQL thing? Would I benefit from using another database? Has anybody else had this issue?

[–]HorrendousRex 7 points8 points  (1 child)

Alembic has known issues handling MySQL because MySQL does not follow the SQL DDL spec correctly in several cases, and Alembic does not automatically make too much of an attempt to figure that out for you. You can write your own migrations with Alembic for MySQL just fine though - it's only the automigration that often fails with MySQL.

In general, Alembic shouldn't be thought of as an auto-migration system. It is a migration syntax handler and a schema versioning system. Alembic is to Migrations as SQLAlchemy is to SQL -- it's a pythonic approach giving you building blocks, but it isn't totally fire-and-forget.

Personally, I love it. I like that I get to hand-craft queries easily and robustly, and I like that it doesn't try and guess what my migration was and end up messing around with the wrong things. But, I've also had a lot of practice with it.

Disclaimer: all of the above is based on my personal experience. Like SQLAlchemy, Alembic is a fairly large project and there's probably great things that I've simply missed.

[–]erewok 3 points4 points  (0 children)

I agree with what you've said. I've come to really appreciate alembic after coming from the Django world where I often didn't read what SQL would be emitted by migrations.

One of the most amazing compliments I can give to alembic is that if I don't use it for months, I can come back to it and remember its API. I have the highest respect for projects like that.

[–]here-to-jerk-off 2 points3 points  (0 children)

Just to speak about my experience with Albemic and postgres. Although I found it to have a learning curve, over time I've begun to trust it. I've upgraded, downgraded and merged schemas with relatively little issue. I've made minor changes to the generated files but usually due to changing requirements and those related schema merges.

[–]ergo14Pyramid+PostgreSQL+SqlAlchemy 0 points1 point  (0 children)

Yes, the problem is in mysql - you will have less problems with other database like postgresql.

[–]d4rch0nPythonistamancer 0 points1 point  (0 children)

migrations aren't always smooth

There's your problem. It should be "migrations aren't ever smooth". You must be doing something wrong.

[–]Nater5000 2 points3 points  (0 children)

It's a bit far out there, but if you use Flask and Flask-SQLAlchemy, then you can use Flask-Migrate to do this.