Skip to content

Commit 68da292

Browse files
authored
Add tox test to check if migrations were missed. (#1081)
* Add tox test to check if migrations were missed. * Document how to contribute migrations.
1 parent 94d42a8 commit 68da292

File tree

3 files changed

+152
-1
lines changed

3 files changed

+152
-1
lines changed

docs/contributing.rst

+18
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ When deploying your app, don't forget to compile the messages with::
9696
django-admin compilemessages
9797

9898

99+
Migrations
100+
==========
101+
102+
If you alter any models, a new migration will need to be generated. This step is frequently missed
103+
by new contributors. You can check if a new migration is needed with::
104+
105+
tox -e migrations
106+
107+
And, if a new migration is needed, use::
108+
109+
django-admin makemigrations --settings tests.mig_settings
110+
111+
Auto migrations frequently have ugly names like `0004_auto_20200902_2022`. You can make your migration
112+
name "better" by adding the `-n name` option::
113+
114+
django-admin makemigrations --settings tests.mig_settings -n widget
115+
116+
99117
Pull requests
100118
=============
101119

tests/mig_settings.py

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
"""
2+
Django settings for CI testing if migrations have been missed.
3+
4+
Generated by 'django-admin startproject' using Django 4.0.1.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/4.0/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
15+
16+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
17+
BASE_DIR = Path(__file__).resolve().parent.parent
18+
19+
20+
# Quick-start development settings - unsuitable for production
21+
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
22+
23+
# SECURITY WARNING: keep the secret key used in production secret!
24+
SECRET_KEY = "django-insecure-9$j0^ot%41l5r(nj9hg02up-n+$59kld!0%l6pvqbd()u%z2as"
25+
26+
# SECURITY WARNING: don't run with debug turned on in production!
27+
DEBUG = True
28+
29+
ALLOWED_HOSTS = []
30+
31+
32+
# Application definition
33+
34+
INSTALLED_APPS = [
35+
"django.contrib.admin",
36+
"django.contrib.auth",
37+
"django.contrib.contenttypes",
38+
"django.contrib.sessions",
39+
"django.contrib.messages",
40+
"django.contrib.staticfiles",
41+
"oauth2_provider",
42+
]
43+
44+
MIDDLEWARE = [
45+
"django.middleware.security.SecurityMiddleware",
46+
"django.contrib.sessions.middleware.SessionMiddleware",
47+
"django.middleware.common.CommonMiddleware",
48+
"django.middleware.csrf.CsrfViewMiddleware",
49+
"django.contrib.auth.middleware.AuthenticationMiddleware",
50+
"django.contrib.messages.middleware.MessageMiddleware",
51+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
52+
]
53+
54+
55+
TEMPLATES = [
56+
{
57+
"BACKEND": "django.template.backends.django.DjangoTemplates",
58+
"DIRS": ["templates"],
59+
"APP_DIRS": True,
60+
"OPTIONS": {
61+
"context_processors": [
62+
"django.template.context_processors.debug",
63+
"django.template.context_processors.request",
64+
"django.contrib.auth.context_processors.auth",
65+
"django.contrib.messages.context_processors.messages",
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = "tutorial.wsgi.application"
72+
73+
LOGIN_URL = "/admin/login/"
74+
75+
# Database
76+
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
77+
78+
DATABASES = {
79+
"default": {
80+
"ENGINE": "django.db.backends.sqlite3",
81+
"NAME": ":memory:",
82+
}
83+
}
84+
85+
86+
# Password validation
87+
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
88+
89+
AUTH_PASSWORD_VALIDATORS = [
90+
{
91+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
92+
},
93+
{
94+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
95+
},
96+
{
97+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
98+
},
99+
{
100+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
101+
},
102+
]
103+
104+
105+
# Internationalization
106+
# https://docs.djangoproject.com/en/4.0/topics/i18n/
107+
108+
LANGUAGE_CODE = "en-us"
109+
110+
TIME_ZONE = "UTC"
111+
112+
USE_I18N = True
113+
114+
USE_TZ = True
115+
116+
117+
# Static files (CSS, JavaScript, Images)
118+
# https://docs.djangoproject.com/en/4.0/howto/static-files/
119+
120+
STATIC_URL = "static/"
121+
122+
# Default primary key field type
123+
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
124+
125+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

tox.ini

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[tox]
22
envlist =
33
flake8,
4+
migrations,
45
docs,
56
py{37,38,39}-dj22,
67
py{37,38,39,310}-dj32,
@@ -10,7 +11,7 @@ envlist =
1011
[gh-actions]
1112
python =
1213
3.7: py37
13-
3.8: py38, docs, flake8
14+
3.8: py38, docs, flake8, migrations
1415
3.9: py39
1516
3.10: py310
1617

@@ -82,6 +83,13 @@ deps =
8283
flake8-quotes
8384
flake8-black
8485

86+
[testenv:migrations]
87+
setenv =
88+
DJANGO_SETTINGS_MODULE = tests.mig_settings
89+
PYTHONPATH = {toxinidir}
90+
PYTHONWARNINGS = all
91+
commands = django-admin makemigrations --dry-run --check
92+
8593
[testenv:build]
8694
deps =
8795
setuptools>=39.0

0 commit comments

Comments
 (0)