diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 35eb1dd..7ddfc9e 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,5 +1,11 @@ + + + + + + diff --git a/core/admin.py b/core/admin.py index 893dcb3..b1dfe16 100644 --- a/core/admin.py +++ b/core/admin.py @@ -13,17 +13,22 @@ UserAdmin as BaseUserAdmin, ) from django.contrib.auth.models import Group +from django.contrib.redirects.models import Redirect from django.db import models from django.utils.translation import gettext_lazy as _ from unfold.admin import ModelAdmin from unfold.contrib.forms.widgets import WysiwygWidget from unfold.decorators import display from unfold.forms import AdminPasswordChangeForm, UserChangeForm - +from django.contrib.redirects.admin import RedirectAdmin as BaseRedirectAdmin from .models import Category, Hackathon, Hacker, School from .models import HackathonLocation +class RedirectAdmin(ModelAdmin, BaseRedirectAdmin): + pass + + class EmailAddressAdmin(BaseEmailAddress, ModelAdmin): pass @@ -155,3 +160,6 @@ class SchoolAdmin(ModelAdmin): admin.site.unregister(EmailAddress) admin.site.register(EmailAddress, EmailAddressAdmin) + +admin.site.unregister(Redirect) +admin.site.register(Redirect, RedirectAdmin) diff --git a/docs/internal/migrations/redirects.md b/docs/internal/migrations/redirects.md new file mode 100644 index 0000000..022bb54 --- /dev/null +++ b/docs/internal/migrations/redirects.md @@ -0,0 +1,77 @@ +# Resolving `django.db.migrations.exceptions.InconsistentMigrationHistory` Error + +If you encounter the error +`django.db.migrations.exceptions.InconsistentMigrationHistory: Migration socialaccount.0001_initial is applied before its dependency sites.0001_initial on database 'default'.` +while migrating, follow these steps to resolve it: + +--- + +## Steps to Resolve + +### 1. Comment Out Apps and Middleware + +Open the **settings file** (`common.py`) and temporarily comment out the following configurations: + +In the `INSTALLED_APPS` section, comment out: + +```python +'django.contrib.sites', +'django.contrib.redirects', +``` + +In the `MIDDLEWARE` section, comment out: + +```python +'django.contrib.redirects.middleware.RedirectFallbackMiddleware', +``` + +After updating the settings, save the file. + +--- + +### 2. Roll Back the Problematic Migrations + +Run the following Django command in your terminal to roll back the `socialaccount` app's migrations to the start (zero): + +```bash +python manage.py migrate socialaccount zero +``` + +This will unapply all migrations related to the `socialaccount` app. + +--- + +### 3. Restore Settings + +After rolling back the migrations, revert the changes you made in `common.py`: + +1. Uncomment `'django.contrib.sites'` and `'django.contrib.redirects'` in the `INSTALLED_APPS` section. +2. Uncomment `'django.contrib.redirects.middleware.RedirectFallbackMiddleware'` in the `MIDDLEWARE` section. + +Save the file. + +--- + +### 4. Reapply Migrations + +Re-run the migrations step-by-step: + +```bash +python manage.py migrate +``` + +This will reapply all migrations in the correct order, resolving the inconsistent migration history. + +--- + +### Summary of Commands + +Here’s a quick list of the commands you’ll need: + +```bash +# Step 2: Roll back socialaccount migrations +python manage.py migrate socialaccount zero + +# Step 4: Reapply migrations +python manage.py migrate +``` diff --git a/fixtures/redirects.json b/fixtures/redirects.json new file mode 100644 index 0000000..a80508b Binary files /dev/null and b/fixtures/redirects.json differ diff --git a/settings/components/common.py b/settings/components/common.py index 45c39b9..7e32656 100644 --- a/settings/components/common.py +++ b/settings/components/common.py @@ -58,6 +58,8 @@ "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", + "django.contrib.sites", + "django.contrib.redirects", "django.contrib.messages", "django.contrib.staticfiles", "django_countries", @@ -112,6 +114,7 @@ # # Eliminate need to provide username, as it's a very old practice # ACCOUNT_USERNAME_REQUIRED = False + MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", @@ -121,6 +124,7 @@ "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "allauth.account.middleware.AccountMiddleware", + "django.contrib.redirects.middleware.RedirectFallbackMiddleware", ] ROOT_URLCONF = "hackathons_canada.urls"