Skip to content
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

Option to Error with Default on New Field #118

Closed
chukkwagon opened this issue Jan 22, 2018 · 3 comments
Closed

Option to Error with Default on New Field #118

chukkwagon opened this issue Jan 22, 2018 · 3 comments
Assignees

Comments

@chukkwagon
Copy link

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.

@atodorov
Copy link
Contributor

@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.

@colinhowe what do you think? Any ideas?

@chukkwagon
Copy link
Author

@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:

migrations.AddField(
    ..., 
    field=<any_field_name>(default=<any_default>)
)

atodorov added a commit that referenced this issue Apr 7, 2018
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.
@atodorov atodorov self-assigned this Apr 7, 2018
@chukkwagon
Copy link
Author

wow thanks for getting to this @atodorov !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants