I'm new with python(don't know anything about it), and also in Django... so question is, what and how, step by step, I need to launch existing Django project which I got from github...
so, what I have done already:
installed python
created virtual environment
run python mange.py migrate, but it showed many errors(and I don't know what to do with it and how to fix them), because I can't even connect to DB(previously I worked with MySQL where I can connect by myself and do selects to check something in DB), but now this project uses SQLite3, and I don't know how I can check this database
run python manage.py runserver and I can see my webapp at localhost...
So, main question is, how to properly launch existing Django project?
Related
I have been trying to setup a django app using this guide:
https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/
And it was a great resource to get everything up and running. However i have problem now when it comes to migrations. Say i add a model, add data into my db, and later i change the model. Now i can run makemigrations using the exec method on the container, but when i shut down my migrations are not stored in my local files i save to my git project, instead they are lost as i spin down the container.
Does anyone know how to solve this, how do you makemigrations is such a setup where you run two dockerized django/postgres dev/prod environments?
Currently I have converted my python 2 project into python 3 project & earlier I was using Django version 1.9.13 & now I have updated it to 2.2.6.
Now I am able to run my project in latest version of python and django but when I run my project in cmd I have found that It showing message like You have 253 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s)... so I have checked my migrations folder and able to find all migrations files there.
Any idea why I am getting such kind of message here & if it is bug then what should I do to get rid of such problem ?
Thanks.
You need to migrate those migrations to your database. This means you have changes in your model classes but they are not applied to the database you are using. To migrate to the database: in CMD
python manage.py makemigrations
python manage.py migrate
In both cases, make sure you are inside your virtualenv (if you have one) and using the right python. For instance, in most cases if you have multiple pythons installed (2 and 3); you might have to use 'python3' in the above commands.
Thanks for taking the time to read this.
I was not happy with TinyMCE extension in django and decided to switch to django-summernote. I first ran
pip uninstall django-tinymce
Removed all mentions of tinymce in the actual project.
Followed the instruction to install django-summernote. Upon completion I decided to run
python manage.py makemigrations
python manage.py migrate
to apply new extension, but get an error:
File "/Users/rasulkireev/Sites/dj-pw/now/migrations/0006_auto_20190703_0134.py", line 4, in <module>
import tinymce.models
ModuleNotFoundError: No module named 'tinymce'
I'm not sure why would Django care about what I did previously since I am simply asking to replace the editor. I can't run python manage.py runserver either.
I can't do anything before fixing this. I beg you guys, please help.
Note: I would ideally want to keep the contents of my current database.
Thanks for taking the time to read this.
Once you have removed all the mentions of tinymce from the models, admins and other files, you need to migrate using a special "flag":
python manage.py makemigrations
python manage.py migrate --fake-initial
I am not to clear on the backend of this method, but it works. You can read more about it the official Django website:
https://docs.djangoproject.com/en/2.2/topics/migrations/
This will make a new initial migration for your app. Now, run python
manage.py migrate --fake-initial, and Django will detect that you have
an initial migration and that the tables it wants to create already
exist, and will mark the migration as already applied. (Without the
migrate --fake-initial flag, the command would error out because the
tables it wants to create already exist.)
Note that this only works given two things:
You have not changed your models since you made their tables. For
migrations to work, you must make the initial migration first and
then make changes, as Django compares changes against migration files, not the database.
You have not manually edited your database - Django won’t be able to detect that your database doesn’t match your models, you’ll just get errors when migrations try to modify those tables.
Hi I am new to Django and have been googling for a whole day without any success.
Basically there is a live/working website built with AngularJS, Django and PostgreSQL (Ubuntu 14.04) and I am trying to download all the files and clone the site into my localhost (Ubuntu 14.04).
After I downloaded the folder and finished install the required packages on my localhost, I run:
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
The server runs without reporting any errors.
However, some of the links are directed to a 404 page, such as this:
http://127.0.0.1:8000/city/chicago
Whereas in the live site, it would direct to the correct working page.
Can someone tell me what may have gone wrong in the process?
Thanks.
Try editing the settings.py file set the DEBUG value to True. Instead of a 404 you should get a full debug of the actual request and see what exactly is missing (I suspect missing data as #NightShadeQueen pointed).
Also you might have a look at django debug toolbar which prints the executed sql queries as well and run them against your local database to see what exactly they return.
recently I started a small Django project that I developed on a local machine using a SQLite3 database and the integrated development server. I now copied the whole project to a server running Debian.
Everything worked well as long as I kept using the SQLite3 database. Now I wanted to switch to a local MySQL database, so I changed the settings.py file in my project's root folder, created the database and added a user. I then ran syncdb and it created the needed tables without any problems.
Now I wanted to use the app, but I keep getting errors, because Django can not find the tables - neither the 'standard tables' like django_sessions nor my own tables - even though they are there (I checked the database).
The one thing that seems awkward about the DatabaseError pages I get is the following line:
Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py in execute, line 234
It seems like Django is still using the SQLite3 backend even though I set it to use the MySQL backend.
The other thing that nearly makes me freak out is this: I deleted the data.sqlite file in my app's root folder using rm. But when I use my app, the file is being recreated!
Can anyone tell me where I went wrong?
When running in production with mod_wsgi or mod_python, new code isn't incorporated until you reload/restart the webserver.
If you are using apache with mod_wsgi, you can also touch the wsgi.py file to restart the python code only.
If running on apache run "sudo /etc/init.d/apache2 reload" everytime you make a change.