django. The manage.py is not working after migrating mysql table - python

I install mysql as my database in my django project.
I did makemigration and migrate it on the django.
After that I wanted to try to run the server, but the python manage.py is not working at all even if there is python stored in my computer.
python_version_in_cmd
I have the screenshot here where it shows no response at all but pip is responding. django
This is my computer environment path computer enviroment path
When I was installing mysql the mysql/python was failing, is that the problem? any hints?

What is the error when running python manage.py runserver? Not knowing that, I could make some guesses.
Make sure your models are setup correctly.
After you get your models written, you can run python manage.py makemigrations
Then you need to run python manage.py migrate in order for the models to be applied to the database.
Some guidance can be found here: https://www.geeksforgeeks.org/django-migrations-python/

Related

Cannot makemigrations on Django Settings already configured error

I'm a new django developer and I recently started a project, and am trying to get the database up and running.
For background: we are using a mysql database for storage, and the settings are configured for it. Using an Unbuntu DO server. I have also been using the virtual environment to run the commands below.
When we initially created the project we ran the makemigrations command, which populated the database with django tables, but not the Models, as we had not made any Models yet. I've now uploaded the Model code, however I could not make any new migrations, I got the error RuntimeError("Settings already configured").
According to this tutorial which I was following (https://www.geekinsta.com/how-to-customize-django-user-model/) some errors are normal and required me to delete and recreate the mysql database (which I did, it has the same name), and clear past migrations (the app/migrations/pycache is now empty). However I'm still experiencing the same error ("Settings already configured").
How can I fix this? I need to successfully run the makemigrations and migrate commands to populate the database. The new database and pycache are empty after I attempted the commands again. Thanks for any and all help.

My django code is requesting a table that doesn't exist

I tried to delete the 'db.sqlite3' file and do the migration again, but it didn't work
If you made changes to your model, you need to run python manage.py makemigrations. If this is a new project that you have never deployed to production, you can delete the migrations folder before running this command.
Then run python manage.py migrate.

how to fix django.db.utils.ProgrammingError:relation "some_object" does not exist?

How to fix django.db.utils.ProgrammingError: relation "some_object" does not exist?
I saw lots of topic on this platform to related this error, but won't able to fix it in my case.
In my case means, I am working on django and I have the postgresql database and It's working well but whenever I took pull request from git(where other person is working) and run the migration then I am getting this error.
below is some links that I had tried
https://stackoverflow.com/a/33055243/11360069 I just try but not working
https://stackoverflow.com/a/46697898/11360069
./manage.py migrate --fake default
https://stackoverflow.com/a/29672770/11360069
python manage.py migrate --run-syncdb and python manage.py migrate --fake appname
python manage.py migrate --fake, python manage.py migrate --fake--initial, python manage.py migrate
Only one way is working for me when I had create a new database and applying migration. But I am not sure that what will happen if, if I'll update this code on server then it will show same error then we can't delete or change the exiting database.

Django Heroku and postgresql

I am new to publishing django apps on heroku.
I have read their tutorials and figured I would start simple by modifying their template django project.
So far everything was good.
Then I made an app as one does, made a model and ran
python3 manage.py makemigrations my_app
python3 manage.py migrate
and things seemed ok.
I then pushed to heroku and there were no immediate complaints.
However, now when I try to make save a new model I get the error:
ProgrammingError at /my_app/
relation "my_app_myappmodel" does not exist
LINE 1: INSERT INTO "my_app_myappmodel" ("field1", "field2", "field3") VALUES...
odd...
So I run this locally and everything works fine.
I have tried cleaning my migrations, faking my migrations, squashing my migrations, etc (as other S.O. posts suggest)
Nothing works.
What is up and how do I fix it?
You need to actually run the migrations on Heroku once you have pushed the code generated by makemigrations. You do this via heroku run manage.py migrate.
run the following command from your terminal
heroku run python manage.py migrate
or you can also do:
in your local settings.py, change your DATABASES variable to use the heroku one then run from the terminal
python manage.py makemigrations
python manage.py migrate
but you should not normally locally make changes to the heroku production database (as in option 2) except if you are really desperate or don't care

Django, reset South migrations

Recently, I moved from Linux Mint to Ubuntu, uploaded my project's code to Github, downloaded it again and tried to continue developing. But I have a problem with South:
I tried migrating the apps(many apps) normally:
manage.py schemamigration apps --auto,
But I got:
"You cannot use --auto on an app with no migrations. Try --initial."
Then I tried '--initial',
But when I migrated the apps '$ ./manage.py migrate apps', I got:
"These migrations are in the database but not on the disk:
...(all the migrations I had, not sure how they ended up there)
I'm not trusting myself; either fix this yourself by fiddling
with the south_migrationhistory table, or pass --delete-ghost-migrations
to South to have it delete ALL of these records (this may not be good)."
I don't care about keeping the migrations so I tried python manage.py --delete-ghost-migrations, but I got "Unknown command".
Then I tried reseting migrations the way this post recommends, so I did:
$ python manage.py reset south
But I got "Unknown command" again.
¿How can I fix this so I can keep working on my project? Sorry if it is something obvious.
*When I was working on Linux Mint I used Mysql, now on Ubuntu I intalled Postgre. This probably doesn't have anything to do with the error cause I think I got it right and configured it correctly with my django project. But maybe you should know it if the solution needs some database manipulation. Thanks in advance.
Use the following command to clear the database:
./manage.py sqlclear south | ./manage.py dbshell
then make sure to remove the migrations directory in the app to fully reset south:
rm [app_name]/migrations

Categories