Adding another application after Django project has already been deployed to production

Hi,

I found that I needed to create a new app containing FAQS page(s) to my Django project after it had already been deployed to production. This is because of my email smtp backend service I will be using. I want to be able to state in the FAQs that people should only sign up for the site if they don’t mind receiving emails about successful registration and if they want to be able to reset their passwords. However, when I did this, I could makemigrations on my new faqs app, but I could not migrate. I got the following errors:

python3 manage.py migrate faqs
/Users/mariacam/Python-Development/django-boards/django_boards/../media media root in development
Traceback (most recent call last):
  File "/Users/mariacam/Python-Development/django-boards/manage.py", line 22, in <module>
    main()
    ~~~~^^
  File "/Users/mariacam/Python-Development/django-boards/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
    ~~~~~~~~~~~~~~~^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/core/management/commands/migrate.py", line 118, in handle
    executor = MigrationExecutor(connection, self.migration_progress_callback)
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
                  ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/db/migrations/loader.py", line 58, in __init__
    self.build_graph()
    ~~~~~~~~~~~~~~~~^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/db/migrations/loader.py", line 235, in build_graph
    self.applied_migrations = recorder.applied_migrations()
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/db/migrations/recorder.py", line 89, in applied_migrations
    if self.has_table():
       ~~~~~~~~~~~~~~^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/db/migrations/recorder.py", line 63, in has_table
    with self.connection.cursor() as cursor:
         ~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/utils/asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/db/backends/base/base.py", line 320, in cursor
    return self._cursor()
           ~~~~~~~~~~~~^^
  File "/Users/mariacam/Python-Development/django-boards/venv/lib/python3.13/site-packages/django/db/backends/dummy/base.py", line 20, in complain
    raise ImproperlyConfigured(
    ...<3 lines>...
    )
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.

I know this is not the ideal way of doing things, but what if one wanted to expand the application after it has already been deployed and has a managed PostgreSQL production database. Locally, I am using the db.sqlite3 database. Thanks!

I guess I could try and create something within my boards app. I initially tried, but I have nested routes in there, and don’t think it would work. I really would need to add a new app. New terms and conditions on these services which I have not used int a WHILE.

Adding an app expects that the INSTALLED_APPS setting be changed to include the new app.

I have seen this type of error getting generated when an “editing error” occurs updating the settings.

I had added it. The I did it I cannot confirm at this point. I removed it, but I did something to my local database db.sqlite3. I also rolled back to a git commit where everything worked nicely, but locally I am being told that I have a lot of migrations. When I run make migrations, nothing happens. When I run migrate, I get a whole bunch of errors regarding the settings.DATABASES is improperly configured. I have a settings directory now and not settings.py. What a nightmare. This is my first real complete django application. I know I did something along the way that was wrong when adding that new application. I am afraid to make anymore changes remotely. I guess I could try and set up a staging environment. Now I have to learn how to do that on Render. Eeeks!

I figured it out. Very easy once I did. First I had to fix my path to my development database inside settings/development.py. Then I ran python manage.py flush which finally worked because I had the correct path to the local database. Then I ran python3 manage.py migrate making sure that in my manage.py file I was pointing to development and not production, and everything was migrated. Somewhere along the way regarding my local database I ended up using the wrong path. But I didn’t realize it because up to the point that I added a new app, nothing had changed and so things worked fine for whatever reason. But now I have fixed it so it will work in perpetuity. This is what I am referring to:

# development.py
from .base import *

# SECURITY WARNING: don't run with debug turned on in production!
# using pyhon-dotenv
DEBUG = os.getenv('DEBUG')

# using decouple to point to ALLOWED_HOSTS env var locally
ALLOWED_HOSTS = config("ALLOWED_HOSTS", cast=Csv())

# For user uploaded files locally
# MEDIA_ROOT = os.path.join(BASE_DIR, "../media")

# the absolute path to media directory
MEDIA_ROOT = os.path.abspath('/Users/mariacam/Python-Development/django-boards/media')
print(MEDIA_ROOT, 'media root in development')

# correct absolute path in which db.sqlite3 resides
CURRENT_DIR= '/Users/mariacam/Python-Development/django-boards/'

# Local Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.sqlite3",
        "NAME": CURRENT_DIR + "db.sqlite3",
    }
}

# Local only
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "../static"),
]

# manage.py
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_boards.settings.development')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

Thanks! You pointed me in the right direction, and I remembered what I should have been checking and then fixing. Thanks! Probably now I can add my new application if I want after I save all my current changes and push to remote!

I just wanted to say, regarding this:

It’s OK to add new Django apps after initial deployment. Websites change and grow all the time, and so creating new apps in a project is very common.

Thanks @ philgyford! I finally figured out what I was doing wrong and fixed it. I even added comments in the code so I would not forget. using a settings directory instead of a settings.py file can be tricky! it was worth the struggle, because now I will NEVER forget.