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:
-
Clone the project.
-
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
-
-
-
Create a virtual environment:
python -m venv ./venv
-
Activate the environment:
source venv_telnyx-invoicing/bin/activate.csh
-
Install requirements:
pip install -r requirements.txt
-
Create a logs directory:
mkdir logs
-
Make migrations:
python manage.py makemigrations
-
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:UsersDominykasPavlijusDesktopTelnyx-Invoicing-1venvLibsite-packagesdjangodbbackendsutils.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:
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….
2
Answers
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:
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.
3. After that I made a —fake migration
4. And after that just to make sure I did migrations like this:
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.
try with this tuto 🙂
Prerequisites
py command should point to python3
py -V
3.10.0
postgresql 16+ must be up and running on your machine with pg_ctl status (Windows), or pgrep -l postgres (Mac), or sudo systemctl status postgresql (Linux)
Git
Create a new folder
mkdir your project && cd your project
Add .gitignore and start git
Add the following .gitignore
.venv
*.sqlite3
pycache
Add your folder to your git
git init
git add . && git commit -m "first commit"
Create virtual environment for Python and activate it
py -m venv .venv
source .venv/bin/activate
Install django and pg driver
py -m pip install django psycopg2-binary
Build django skeleton
Below, "core" means the core of our app, "." means build skeleton inside the current folder :
django-admin startproject core .
git add . && git commit -m "django first files"
Change settings.py
Inside settings.py, add localhost to the list of allowed hosts, like this :