You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When adding a column to an existing table with a default value, django will lock the table while performing the update. Django best practices are to create a new column with null=True and no default value.
Can you add an option to lint for this best practice. Deploying to a production server with a default value set has a high probability of resulting in downtime.
The text was updated successfully, but these errors were encountered:
@chukkwagon how do we know a column has been newly added ?
pylint_django can probably run this sort of check only against fields which are inside a migration module/class and I have no idea how accurate that may or may not be. In all other cases I don't think the code would make a difference between an existing field and a newly added one.
Note: We can easily make a plugin for that (with or without the migrations specifics) but I'm definitely not in favor of teaching pylint_django recognize whether or not a column has been added beyond a couple of if statements.
@atodorov exactly, I was thinking it would need to lint migration files. The pattern for a new field with a default would be that the migration file would contain the following (generalized) operation:
Enables checking of migrations and reports when there's an
AddField with a default value which may slow down applying
migrations on large tables. This may also lead to production tables
being locked while migrations are being applied.
When adding a column to an existing table with a default value, django will lock the table while performing the update. Django best practices are to create a new column with
null=True
and no default value.Reference:
Stack Overflow Summary
Django Docs
Can you add an option to lint for this best practice. Deploying to a production server with a default value set has a high probability of resulting in downtime.
The text was updated successfully, but these errors were encountered: