I am attempting to run a site from my localhost. What I did is I first cloned the repo and pull it into my local directory. Then, I changed the DB part to my DB settings. I have tried python manage.py runserver, python manage.py migrate and python manage.py makemigrations, but it still shows the same error.
error
I have tried different solutions found online, but they don't seem to work. I think the main problem is that I'm not sure where the problem is. I have tried creating a superuser, but it still shows the same error.
So I have deployed my Django project to Heroku, and now trying to migrate the database. I have everything working fine in my local sever. Then I tried to run the commands in heroku, as below.
heroku run python manage.py makemigrations app_name'.
This worked fine.
Migrations for 'app_name':
contents\migrations\0001_initial.py
- Create model Book
- Create model Category
- Create model Content
Then of course, I tried : heroku run python manage.py migrate app_name.
But then I got this error CommandError: App 'app_name' does not have migrations.
I've done some research for possible issues, none of which were relevant to mine.
For example I do have __init__.py in the migrations folder inside app_name directory. Also, I've tried heroku run python manage.py migrate as well as heroku run python manage.py migrate app_name. I'm very confused. What do you think is the problem? Thanks in advance. :)
I had the same problem, I don't know why, but the following works for me (two commands in one line):
python manage.py makemigrations && python manage.py migrate app_name
As explained in heroku's help article Why are my file uploads missing/deleted?:
The Heroku filesystem is ephemeral - that means that any changes to
the filesystem whilst the dyno is running only last until that dyno is
shut down or restarted.
That is you do generate the migration files but they cease to exist shortly after when the app is reloaded.
In general the strategy you take is not a good approach to migrations as this can cause various issues, let's say you have multiple production servers each generates their own migrations this causes a conflict! In your situation suppose you do migrate this way and then later you want to add some new models this again will cause you problems.
One should always add their migrations to the version control (git, etc.) commit them and push them to production (here your heroku dyno). That is run python manage.py makemigrations locally, commit the generated migrations, push them and then run heroku run python manage.py migrate.
When I enter the commands python manage.py makemigrations and python manage.py migrate all accounts are deleted from the database. Perhaps the database is simply re-created
UPD. Screenshot
Hi #AleRyp and welcome to stackoverflow.
Usually
./manage.py makemigrations
does nothing unless you don't have changes in your models.
Instead
./manage.py migrate
does something only there're new migrations to be applied.
Would be nice to see the output of both commands in your case
After I installed django i wrote the start project command to verify django is working or not.
i.e,
django-admin startproject mysite
cd mysite
python manage.py runserver
After that I got an IP address(http://127.0.0.1:8000/)
but when i link to this http://127.0.0.1:8000/, it is showing unable to connect. what should i do now?
Don't worry this is not a big issue!
As per your comment mentioned above, Run the python manage.py runserver then go to new instance of powershell and do other stuff what you want to try.
Let that runserver window isolated.
So I ran my program based on from here and It worked without any error. I go to to /admin. I login. So far everything is good. Then when it loads I get this:
I checked the traceback (which is really long) and none of includes my code. It doesn't tell me what part of the code this error is occurring in so I don't know how to approach this. Please explain what this is, why this is happening, and how I can fix it.
If you need any part of my code, just ask in comments because I don't know where this is happening.
You need to run migrate command in-order to force django to create auth tables.
python manage.py migrate
Then for any change you made on models, don't forget to run these two commands.
python manage.py makemigrations
python manage.py migrate
Use pip install django==2.1.5
If the problem persists,
Use python manage.py migrate --run-syncdb
by default, the auth table is not created in the database
so first we need to create the table and reload the page
to achieve the same
make the migrations by typing the following command
1. python3 manage.py makemigrations
2. python3 manage.py migrate
Till the time they don't debug this issue with Django and Sqlite3 use the older versions of Django
You may consider using version 1.10.5(using command pip install --upgrade django==1.10.5)
yes, that was fault of django version ,when i installed django==2.1.5 that problem was solved.
Install latest django version
$ pip3 install django==2.2.8
$ python3 manage.py makemigrations
$ python manage.py migrate
then reload page in browser
this is the problem with migration just type the following command:-
python manage.py migrate
If you still get error after you lunched
python manage.py migrate
and for every change you made on models
python manage.py makemigrations
python manage.py migrate
Then check if you have Django version older than 2.1.5, because this latter version fixes a bug returning "OperationalError>no such table" when adding an object to your database as superuser.
So try to
pip install Django==2.1.5
However, you will have to re-write your project anew.
user permission
Hi
In Django Administration :check if the user has the right permission, it should work
use these commands
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py runserver