djangopostgresqldjango-modelspgadmin

Django cloned project does not give tables after migrating


I cloned a project that I want to modify and experiment with, and I have all the necessary credentials. However, I'm encountering issues while following the steps outlined in the ReadMe.md file since I cloned it:

  1. Clone the project.

  2. Create a .env file and add the following information:

    • Database variables:

      • DATABASE_NAME: Database name

      • DATABASE_USER: Database user

      • DATABASE_PASSWORD: Database password

      • DATABASE_HOST: Database host

      • DATABASE_PORT: Database port

    • Authentication variables for the Telnyx API:

      • Telnyx_v2_key: Telnyx API v2 key

      • x-api-token: Telnyx API v1 token

      • x-api-user: Telnyx API v2 user email

  3. Create a virtual environment: python -m venv ./venv

  4. Activate the environment: source venv_telnyx-invoicing/bin/activate.csh

  5. Install requirements: pip install -r requirements.txt

  6. Create a logs directory: mkdir logs

  7. Make migrations: python manage.py makemigrations

  8. Migrate: python manage.py migrate

I’m currently stuck at the migration step. When I try to run python manage.py makemigrations, I receive the following error:

Traceback (most recent call last):
  File "C:\Users\DominykasPavlijus\Desktop\Telnyx-Invoicing-1\venv\Lib\site-packages\django\db\backends\utils.py", line 105, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.UndefinedTable: relation "Project_tenant" does not exist
LINE 1: ...nant"."id", "Project_tenant"."billing_group" FROM "Project_t...

My settings.py file appears to be configured correctly:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.getenv('DATABASE_NAME'),
        'USER': os.getenv('DATABASE_USER'),
        'PASSWORD': os.getenv('DATABASE_PASSWORD'),
        'HOST': os.getenv('DATABASE_HOST'),
        'PORT': os.getenv('DATABASE_PORT'),
    }
}

This is the model that is causing the issue:

from django.db import models
from cgi import print_exception
from enum import unique
from unicodedata import name

    class Tenant(models.Model):
        billing_group = models.CharField(max_length=200)

    def __str__(self):
        return str(self.billing_group)

I tried looking at the guides, but nothing seemed correct, makemigrations isn't creating tables in my database, let me know if I am missing something on a first time clone, maybe a step or something?

There are no migration files or folders in this project and this is what my project folder looks like:

Projects folder

The only way it works without errors the migrations I mean is if I get the backup of the production and upload it to my pgadmin....

UPDATE: I don't know but could this be what is giving the error?:

from django.contrib import admin
from django.urls import path
from django.urls import include
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    path('admin/', admin.site.urls),
    # path('', include('Project.urls')),
    path('', include('users.urls')),
    path('', include('callrates.urls')),
    # path('', include('phoneNumbers.urls')),
    # path('', include('reports.urls')),
]

urlpatterns += staticfiles_urlpatterns()

If I uncomment the parts that are commented out now I get the error, if they are commented out then migrations run, not all, but run....


Solution

  • UPDATE: After going through all the guides and gathering information, I found that the only way it worked without any errors was by following these steps:

    Step by step of what I have done:

    1. In git bash I have filled in these commands so that all pf the folders would have a migrations folder with init.py file in them:

      mkdir -p callrates/migrations && touch callrates/migrations/init.py`

      mkdir -p phoneNumbers/migrations && touch phoneNumbers/migrations/init.py

      mkdir -p Project/migrations && touch Project/migrations/init.py

      mkdir -p reports/migrations && touch reports/migrations/init.py

      mkdir -p users/migrations && touch users/migrations/init.py

    2. Then I made migrations by skipping checks, which finally gave me the tables.

    python manage.py makemigrations --skip-checks
    python manage.py migrate --skip-checks
    

    3. After that I made a —fake migration

    python manage.py migrate --fake
    

    4. And after that just to make sure I did migrations like this:

    python manage.py makemigrations
    python manage.py migrate
    

    I realize that the tables were initially empty, which probably wasn’t the ideal solution, but it worked for me. Later, I imported data into each table, and now everything is working as expected.