New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server default not matching for func.now()
with SQLite
#634
Comments
hi - what Alembic and SQLAlchemy versions please ? |
also please try going into your model and setting up the column as:
please do not consider this as a solution proposal, this is only to see if this resolves the problem as a means to identify its source |
Add explicit test to confirm the issue described in #634 is not reproducible. Change-Id: I31c9ba35c501fef0958f15d122ea1674a171d78e
this issue is not reproducible with current Alembic / SQLAlchemy versions and the issue you describe seems to match what was fixed in #579, so ensure you are on the latest 1.3.1 release. |
Very strange. Alembic was not even installed into that virtual environment until yesterday and I can see in my terminal session that alembic-1.3.1 sqlalchemy-1.3.11 were installed yesterday afternoon before I started using them. I have, however, just updated pytest (along with more-itertools, zipp, importlib-metadata, pluggy, py, pyparsing, packaging, pytest, pytest-flask) and the issue has gone away. I don't see how any of those would alter the way that alembic works, but it looks like it's working as intended now. Apologies for the non-issue and thanks for the quick response. PS I had tried |
What I always do is, use the python interpreter that I'm dealing with, I type "import alembic" and then " |
Hi, I met the same issue recently after an update. Not sure if it exists prior to the update, but here's what I have:
table definition:
alembic auto-generated upgrade script:
error message when rolling out the upgrade:
The upgrade works fine with Postgres but I got the above error with SQLite. It looks like the script generated for SQLite has syntax error. I looked at a few other issue threads and tried to manually execute the script in SQLite with I'm wondering if this is intended, or is there anything wrong? Thanks in advance! |
the func. constructs generate as text("...") that is hardcoded to the target database which you autogenerated against. so you are probably autogenerating against Postgresql. To have it run on SQLite you should edit your migration script to use func.now() directly so that it renders SQLite's "CURRENT_TIMESTAMP" when run on that backend. |
It works! Thanks! I'm wondering why it isn't the default behavior to generate a generic migration script rather than a dialect-specific one? |
because that is much more difficult to implement such that it works in all cases. for simple func.xyz() maybe not so bad but for any SQL expression more complicated with that we have to reverse-engineer printing out complete Python SQLAlchemy expressions. if your server default was for example "server_default=func.my_special_proc(func.status() +12) + 18", we would have to read in that whole SQLAlchemy expression and build out a whole new Python compilation system for it that spits out valid Python / SQLAlchemy code. |
That makes a lot of sense. Thanks! |
My model has
And every time I invoke
autogenerate
withcompare_server_default=True
on sqlite, it generates the same migrations that do nothing:The text was updated successfully, but these errors were encountered: