Comments (6)
Yes, that's good, and you can run make style ci
before commit, thanks for contribution!
from aerich.
Can you show model difference before and after?
from aerich.
From migrations/old_models.py
# Before:
class ConfirmationCode(BaseAbstractModel, GetCredentialMixin):
value = fields.CharField(
max_length=8,
default=lambda: ''.join(random.choice(string.digits) for i in range(8)),
unique=True,
)
# Relations
email = fields.ForeignKeyField(
model_name="diff_models.Email",
related_name="tokens",
null=True,
)
phone = fields.ForeignKeyField(
model_name="diff_models.Phone",
related_name="tokens",
null=True,
)
type = fields.ForeignKeyField(model_name="diff_models.ConfirmationCodeType")
class Meta:
table = "confirmation_code"
# After
class ConfirmationCode(BaseAbstractModel, GetCredentialMixin):
value = fields.CharField(
max_length=8,
default=lambda: ''.join(random.choice(string.digits) for i in range(8)),
unique=True,
)
fale_field_to_create_migration = fields.IntField(null=True)
# Relations
email = fields.ForeignKeyField(
model_name="diff_models.Email",
related_name="tokens",
null=True,
)
phone = fields.ForeignKeyField(
model_name="diff_models.Phone",
related_name="tokens",
null=True,
)
type = fields.ForeignKeyField(model_name="diff_models.ConfirmationCodeType")
class Meta:
table = "confirmation_code"
Generated migration:
{
"upgrade": [
"ALTER TABLE \"confirmation_code\" ALTER COLUMN \"value\" DROP DEFAULT",
"ALTER TABLE \"confirmation_code\" ALTER COLUMN \"value\" TYPE VARCHAR(8)",
"ALTER TABLE \"confirmation_code\" ADD \"fale_field_to_create_migration\" INT"
],
"downgrade": [
"ALTER TABLE \"confirmation_code\" ALTER COLUMN \"value\" DROP DEFAULT",
"ALTER TABLE \"confirmation_code\" ALTER COLUMN \"value\" TYPE VARCHAR(8)",
"ALTER TABLE \"confirmation_code\" DROP COLUMN \"fale_field_to_create_migration\""
]
}
from aerich.
Hi, thank you for the great tool! I have the same issue for the case where default
=callable, I just wondering why the call for callable is omitted here?
Line 69 in 9879004
Can we add more sophisticated handling for callables as defaults?
from aerich.
default
generated in migrations is affected in database, obviously database can't support callable
default.
from aerich.
@long2ice yes, you are right, sorry for the confusion, I said about change handling callable defaults in detect migrations, as an example this fix solve my issue:
Instead of:
Line 350 in a677d50
I use :
if new_field.default != old_field.default and not callable(
new_field.default
):
What do you think about this change? I can make PR if you are ok with this
The main point: we shouldn't detect changes for callables in migrations
from aerich.
Related Issues (20)
- varchar max_length change not detected HOT 2
- Improved feedback for "migrate" when models and schema are in sync
- aerich inspectdb makes syntax error
- Pydantic validation error when inspecting DB HOT 4
- AttributeError: 'method_descriptor' object has no attribute '__module__'. Did you mean: '__reduce__'? HOT 1
- stuck on init HOT 13
- FK column rename error
- FK column unique not working
- migrate() got an unexpected keyword argument 'empty' HOT 2
- Model with multiple FKs to same table throws error or finds changes that aren't there
- Insert into a glossary table HOT 1
- Support altering columns in SQLite migrations by RENAME-ADD-UPDATE-DROP HOT 1
- Setting null = false on m2m fields causes migration to fail
- Multiple database HOT 2
- Migrate from `CharField(...,unique=True)` to `CharField(...,unique=False)` raises tortoise.exceptions.OperationalError HOT 1
- `make test_postgres` failed with `tortoise-orm>=0.21`
- UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 84: character maps to <undefined>
- Support 3.12.4
- Error reported when add and modify many to many relationships
- RuntimeWarning: Module "x.x.x" has no models HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aerich.