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

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.

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

How to decouple local directory and Heroku project

I am developing an app with Django and I successfully pushed it on Heroku.
This app has a postgres database and a form to allow users to fill the database.
I have coupled the local directory and Heroku, so that both if I run the server by command prompt, or if I access the app, and submit the form, my database get changed.
Now I want to make some experiments on the local database without changing the one on Heroku.
Is it possible?
Can I do it by just commenting the database URL in settings.py ?
I have searched for this matter on Google but I don't know the name it, so that I cound not find proper answer.
This is not a question of "decoupling" directories. It is because you are trying to use sqlite on Heroku, and you have added the sqlite file to your git repo.
You cannot use sqlite on Heroku; use the postgres add-on. Additionally, your sqlite file must not be in source control.

PyCharm professional edition cannot support Django

I have PyCharm professional edition, and I have been trying to PyCharm and Django. However, it seems that I could not enable Django support in PyCharm. As shown in the following figure, when I try to enable Django support in the PyCharm setting, there is nothing shown for Django.
Can anyone help me identify the issue?
That's because you haven't created a project yet. You get this screen because you're still in the step before creating a project.
Create a new project
Select Django on the left column
Enter a name for your project
Select (or create on the fly) a virtualenv
Click the Create button
Now, after project has been created, you can go to Languages & Frameworks => Django and then enable the Django support by selecting your project root directory and your settings.py file.

Django. Heroku. Delete migrations on Heroku

I want to add a couple of new fields to my app in Heroku. I wouldn't like to lose the data I have there. So, I tried using South but it kept giving me errors, it looks like I made a mistake somewhere and now I need to delete the migrations and try again. In a local environment this is done by deleting the migrations folder and dropping the south_migrationhistory tables. I am new to Heroku, I guess the commands are similar, but I can't seem to find them. Thanks in advance for your help.
Heroku comes with the ability to run a unix shell remotely, it works pretty much like ssh.
Just type heroku run bash in a terminal (from the git repo of your project of course), and you will end up with a bash prompt that can be used to explore the file system and process environment of your project, including South migration files.
Hope this helps.

django SQL Console

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.