From 43535c48273905305ca1dfe40a40c371fa8a5a02 Mon Sep 17 00:00:00 2001 From: realpython-bot <42617967+realpython-bot@users.noreply.github.com> Date: Fri, 16 Oct 2026 16:11:54 +0000 Subject: [PATCH] Update django-migrations to Django 6.1 Regenerate the bitcoin_tracker project scaffold on Django 6.1.2 (adds asgi.py, current settings/urls/wsgi/manage.py) and regenerate both migrations so they match what the updated Django Migrations: A Primer tutorial shows. Pin Django, asgiref, and sqlparse in requirements.txt and refresh the README setup instructions. --- django-migrations/README.md | 22 +++++-- .../bitcoin_tracker/bitcoin_tracker/asgi.py | 16 ++++++ .../bitcoin_tracker/settings.py | 57 +++++++++++-------- .../bitcoin_tracker/bitcoin_tracker/urls.py | 9 ++- .../bitcoin_tracker/bitcoin_tracker/wsgi.py | 2 +- .../migrations/0001_initial.py | 25 +++----- .../migrations/0002_switch_to_decimals.py | 12 ++-- django-migrations/bitcoin_tracker/manage.py | 10 +++- django-migrations/requirements.txt | 3 + 9 files changed, 102 insertions(+), 54 deletions(-) create mode 100644 django-migrations/bitcoin_tracker/bitcoin_tracker/asgi.py create mode 100644 django-migrations/requirements.txt diff --git a/django-migrations/README.md b/django-migrations/README.md index 9012dd1030..0244d3857c 100644 --- a/django-migrations/README.md +++ b/django-migrations/README.md @@ -6,10 +6,22 @@ It is also used in the follow up article [Digging Deeper into Migrations](https: **Note:** The code in this directory has been reformatted with black and might therefore differ slightly in codestyle from the code originally generated by Django. -## Installation +## Setup -This Project has been tested with Python 3.6 and Django 2.1, but you should be able to run it with an Django 2.x and a compatible Python. The recommended way to install it is using `pip` and a virtualenv: +This project has been tested with Python 3.14 and Django 6.1. Create and activate a virtual environment, then install the pinned dependencies: - $ python3 -m venv .venv - $ source .venv/bin/activate - (.venv) $ pip install "Django==2.*" +```console +$ python -m venv venv/ +$ source venv/bin/activate +(venv) $ python -m pip install -r requirements.txt +``` + +## Usage + +Apply the migrations and inspect them: + +```console +(venv) $ cd bitcoin_tracker/ +(venv) $ python manage.py migrate +(venv) $ python manage.py showmigrations historical_data +``` diff --git a/django-migrations/bitcoin_tracker/bitcoin_tracker/asgi.py b/django-migrations/bitcoin_tracker/bitcoin_tracker/asgi.py new file mode 100644 index 0000000000..7318d6bfdb --- /dev/null +++ b/django-migrations/bitcoin_tracker/bitcoin_tracker/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for bitcoin_tracker project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/6.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bitcoin_tracker.settings") + +application = get_asgi_application() diff --git a/django-migrations/bitcoin_tracker/bitcoin_tracker/settings.py b/django-migrations/bitcoin_tracker/bitcoin_tracker/settings.py index 7b3748cdce..01dc9dd82f 100644 --- a/django-migrations/bitcoin_tracker/bitcoin_tracker/settings.py +++ b/django-migrations/bitcoin_tracker/bitcoin_tracker/settings.py @@ -1,26 +1,28 @@ """ Django settings for bitcoin_tracker project. -Generated by 'django-admin startproject' using Django 2.1.5. +Generated by 'django-admin startproject' using Django 6.1.2. For more information on this file, see -https://docs.djangoproject.com/en/2.1/topics/settings/ +https://docs.djangoproject.com/en/6.1/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/2.1/ref/settings/ +https://docs.djangoproject.com/en/6.1/ref/settings/ """ -import os +from pathlib import Path -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/6.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "dyf)n0fejvk73!&k5_uq4ce7=e6-0+7sy)rm$w=@rg_!xk!5n3" +SECRET_KEY = ( + "django-insecure-+_s6u_^v+)og2673_%l$1iazz%uld)%=f6v_(e)ch0$btj0u7=" +) # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True @@ -59,48 +61,49 @@ "APP_DIRS": True, "OPTIONS": { "context_processors": [ - "django.template.context_processors.debug", "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", - ] + ], }, - } + }, ] WSGI_APPLICATION = "bitcoin_tracker.wsgi.application" # Database -# https://docs.djangoproject.com/en/2.1/ref/settings/#databases +# https://docs.djangoproject.com/en/6.1/ref/settings/#databases DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "db.sqlite3"), + "NAME": BASE_DIR / "db.sqlite3", } } # Password validation -# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/6.1/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" + "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", + }, + { + "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator", }, - {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"}, { - "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator" + "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator", }, { - "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator" + "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator", }, ] # Internationalization -# https://docs.djangoproject.com/en/2.1/topics/i18n/ +# https://docs.djangoproject.com/en/6.1/topics/i18n/ LANGUAGE_CODE = "en-us" @@ -108,12 +111,20 @@ USE_I18N = True -USE_L10N = True - USE_TZ = True # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/2.1/howto/static-files/ +# https://docs.djangoproject.com/en/6.1/howto/static-files/ + +STATIC_URL = "static/" -STATIC_URL = "/static/" + +# Email +# https://docs.djangoproject.com/en/6.1/topics/email/#topic-email-configuration + +MAILERS = { + "default": { + "BACKEND": "django.core.mail.backends.console.EmailBackend", + }, +} diff --git a/django-migrations/bitcoin_tracker/bitcoin_tracker/urls.py b/django-migrations/bitcoin_tracker/bitcoin_tracker/urls.py index 1903c817b4..7a18e7c693 100644 --- a/django-migrations/bitcoin_tracker/bitcoin_tracker/urls.py +++ b/django-migrations/bitcoin_tracker/bitcoin_tracker/urls.py @@ -1,7 +1,8 @@ -"""bitcoin_tracker URL Configuration +""" +URL configuration for bitcoin_tracker project. The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/2.1/topics/http/urls/ + https://docs.djangoproject.com/en/6.1/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views @@ -17,4 +18,6 @@ from django.contrib import admin from django.urls import path -urlpatterns = [path("admin/", admin.site.urls)] +urlpatterns = [ + path("admin/", admin.site.urls), +] diff --git a/django-migrations/bitcoin_tracker/bitcoin_tracker/wsgi.py b/django-migrations/bitcoin_tracker/bitcoin_tracker/wsgi.py index b44ed99a81..2f83792630 100644 --- a/django-migrations/bitcoin_tracker/bitcoin_tracker/wsgi.py +++ b/django-migrations/bitcoin_tracker/bitcoin_tracker/wsgi.py @@ -4,7 +4,7 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see -https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/6.1/howto/deployment/wsgi/ """ import os diff --git a/django-migrations/bitcoin_tracker/historical_data/migrations/0001_initial.py b/django-migrations/bitcoin_tracker/historical_data/migrations/0001_initial.py index 1b53a6925d..c45f109325 100644 --- a/django-migrations/bitcoin_tracker/historical_data/migrations/0001_initial.py +++ b/django-migrations/bitcoin_tracker/historical_data/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 2.1.5 on 2019-02-05 20:23 +# Generated by Django 6.1.2 on 2026-10-16 16:11 from django.db import migrations, models @@ -7,24 +7,17 @@ class Migration(migrations.Migration): initial = True - dependencies = [] + dependencies = [ + ] operations = [ migrations.CreateModel( - name="PriceHistory", + name='PriceHistory', fields=[ - ( - "id", - models.AutoField( - auto_created=True, - primary_key=True, - serialize=False, - verbose_name="ID", - ), - ), - ("date", models.DateTimeField(auto_now_add=True)), - ("price", models.DecimalField(decimal_places=2, max_digits=7)), - ("volume", models.PositiveIntegerField()), + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('date', models.DateTimeField(auto_now_add=True)), + ('price', models.DecimalField(decimal_places=2, max_digits=7)), + ('volume', models.PositiveIntegerField()), ], - ) + ), ] diff --git a/django-migrations/bitcoin_tracker/historical_data/migrations/0002_switch_to_decimals.py b/django-migrations/bitcoin_tracker/historical_data/migrations/0002_switch_to_decimals.py index 365924d104..2597023d2a 100644 --- a/django-migrations/bitcoin_tracker/historical_data/migrations/0002_switch_to_decimals.py +++ b/django-migrations/bitcoin_tracker/historical_data/migrations/0002_switch_to_decimals.py @@ -1,16 +1,18 @@ -# Generated by Django 2.1.5 on 2019-02-05 20:26 +# Generated by Django 6.1.2 on 2026-10-16 16:11 from django.db import migrations, models class Migration(migrations.Migration): - dependencies = [("historical_data", "0001_initial")] + dependencies = [ + ('historical_data', '0001_initial'), + ] operations = [ migrations.AlterField( - model_name="pricehistory", - name="volume", + model_name='pricehistory', + name='volume', field=models.DecimalField(decimal_places=3, max_digits=7), - ) + ), ] diff --git a/django-migrations/bitcoin_tracker/manage.py b/django-migrations/bitcoin_tracker/manage.py index df9510487c..50dfac7be1 100755 --- a/django-migrations/bitcoin_tracker/manage.py +++ b/django-migrations/bitcoin_tracker/manage.py @@ -1,8 +1,12 @@ #!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" + import os import sys -if __name__ == "__main__": + +def main(): + """Run administrative tasks.""" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "bitcoin_tracker.settings") try: from django.core.management import execute_from_command_line @@ -13,3 +17,7 @@ "forget to activate a virtual environment?" ) from exc execute_from_command_line(sys.argv) + + +if __name__ == "__main__": + main() diff --git a/django-migrations/requirements.txt b/django-migrations/requirements.txt new file mode 100644 index 0000000000..caaa1b5bb3 --- /dev/null +++ b/django-migrations/requirements.txt @@ -0,0 +1,3 @@ +asgiref==3.12.1 +Django==6.1.2 +sqlparse==0.6.0