django SQL Console - django

I am trying to debug a piece of SQL that is coming back incorrectly. I am not sure if django or mysql is handling it wrong so I want to run it through a django console.
Is there a way to set this up?
Thanks in advance.

manage.py dbshell or manage.py shell shell being going into the python interpreter loading your project settings, dbshell putting you in the database cli client. django.db.queries holds the queries that django creates. bigmattyh's suggestion of debug toolbar is a good one, but not interactive.

A good place to start is to install the django debug toolbar in your project. It provides an unobtrusive interface that gives you access to the SQL queries so you can hunt down what's happening at that level.

Related

How to migrate a Django app with postgres database

I have just inherrited a jDango app with .tar.gz compression extention and a .sql file which is a postgreSQL database dump. My mission which I did not choose to accept is to somehow find its way onto AWS. I'm not familier with Django. I believe the app was built with the Ubuntu OS.
I thought that maybe the best thing would be to get postgreSQL and Django working on my local machine. I have all working in vanilla on Windows, and Ubuntu (virtual box) and have set up Amazon Lightsail with a postgreSQL database..
I'm a bit stuck as to what to do next to migrate the app. Would it all be CLI/Cmd Prompt/Terminal or is there a procedure I should be using.
I'm guessing it's not as simple as importing the database and then copying files over and replacing existing vanilla Django ones? Any pointers would be of great help. Thanks.
Open your editor terminal and write code below:
python manage.py makemigrations
python manage.py migrate

PyCharm does not automatically recognize a sqlite3 database inside a Django project

I am following a Django tutorial. After creating the project tictactoe, I opened it using PyCharm professional
According to some PyCharm tutorials the database should be automatically recognised and should appear on the database windows. This is not the case.
According to other PyCharm tutorials I should be able to drag the db.sqlite3 file into the database windows to automatically connect to the database and this is also not working.
Could someone guide me step by step and explain how do I connect to the DB and how I visualise its content?
Thank you for your help
In order to create a db you have to run the command python manage.py migrate in your command prompt or terminal
You need to click the + button, then Data Source, and in your case, select SQLite from the dropdown. After that, in the new window, select the actual db.sqlite3 file.

Running Django's createsuperuser in Google Cloud Run

I'm trying to run a Django app on Google Cloud Run. The site itself works nicely, can run migrations and collect static assets via a startup script. The one thing I cannot figure out how to do is create a superuser. This requires interactively typing in a password or at least setting it via a django shell. I currently cannot figure out how to do this and it seems like it might not be possible; which would make Cloud Run unusable for Django. Has anyone been able to achieve this or have a sustainable workaround? Thanks!
Instead of Django Shell use the api to create the superuser. Once you have the script make it part of the container build process.

How to make the Django light weight server loads quickly

When I run my Django Project in my local, Using Python manage.py runserver
It takes too long to load, or reload after a change is made in the local *.py files.How Do i make it faster, So I can quickly reload my project when ever a file is changed.
It could be taking a while due to time of database connections opening. Are you running your database locally?
You can also enable things like auto-reload based on code changes by installing the django-extensions and using ./manage.py runserver_plus.
Also look at using the django-debug-toolbar to profile SQL queries and look at what is coming through to your app.

can't get django to work in eclipse + windows

I've installed django on my windows machine, added the pydev and django plugins for eclipse, create a django project, and ran manage.py createapp to create one app. Now when I run manage.py runserver (via eclipse's "custom command" option") It says Validating models... but when I go to http://localhost:8000 I get no response, as though the server is not running. What am I doing wrong?
Try running with --noreload to avoid getting two processes. It helps with error output redirection in eclipse, and may give you more hints towards the actual problem.
Also, do the same from the command-line to see if you get the same problem.
Update: Per Fabio's comment above, you can work around this problem by hacking the code, as explained in this question.