I’ve just started learning Django.
I’ve finished the Overview and the Installation parts as well as Part 1 of the tutorial.
At the end of the database setup in Part 2 of the tutorial there is described how the migrate command works.
And then there is the follwing text, describing the how to run the command-line client for the database:
If you’re interested, run the command-line client for your database and type
SHOW TABLES; (MariaDB, MySQL),
.schema (SQLite), or
SELECT TABLE_NAME FROM USER_TABLES; (Oracle) to display the tables Django created.
On Windows 10 PowerShell I’ve tried
py manage.py migrate \dt .schema
which gave me a
CommandError: No installed app with label '\dt'.
Then I’ve used the search engine to search for
command-line client django an I found the dbshell in the Django Docs which says that
django-admin dbshell runs the command-line client for my database.
Therefore I’ve tried to run
django-admin dbshell \dt .schema which resulted in this exception:
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I absolutely don’t understand how this part of the tutorial works.
However I think I actually don’t need to go on in the tutorial and to complete it.
Actually I just wanted to let people know that this part is confusing and didn’t work for me as a beginner in Django.
Therefore I hope this here is the right place for that.
If you have an app named
dt, the app is
dt, not `\dt’
The help block before that referring to the
\dt command is the command you would use in the PostgreSQL shell (psql) and not the manage.py command. That’s different from, and not directly related to the powershell command you’re trying to run.
If you’re following the tutorial, follow the tutorial exactly. Don’t confuse yourself by trying to merge information from multiple sources.
Thanks for your quick reply.
You are right - including the
\dt was unmindful and not what they instruct in the tutorial.
However I don’t understand the following part of the instructions:
run the command-line client for your database
I don’t know how to do that.
And - as far as I know - it was not described in the tutorial before.
I found instructions on how to launch sqlite3 for django.
With your help and these instructions I assumed that the django tutorial (part 2) wants me to type
py manage.py dbshell .schema in my PowerShell to run the command-line client for SQLite.
The command above results in the following error:
CommandError: You appear not to have the 'sqlite3' program installed or on your path.
So did I follow the instructions correctly now?
And why didn’t it work for me then, if SQLite is included in Python (due to the tutorial)?
It’s not really part of the tutorial. It’s a side-bar comment regarding ways you can verify what has been done. It’s also completely outside the scope of the tutorial, since it has nothing to do with Python or Django.
Exactly how you do it depends upon the combination of what operating system you’re using and the database involved. For example, if you’re on Linux and you want to use the command-line client for PostgreSQL, you would run the command “psql”. That command is part of PostgreSQL, and not part of your Python or Django installation. You can, in fact, run Django perfectly well without having that command installed on your system.
Again, that command you found is from yet another source - a third party library providing a different set of tools and commands. (In this case, it is accurate, but still, mixing sources at this stage is more likely to create confusion than not.)
The SQLite library for Python is part of python, while the sqlite3 command is part of sqlite. See SQLite Download Page for files to install along with other documentation about sqlite.
Additionally, you can run every manage.py command with the -h parameter to get help about the individual commands. If you were to run manage.py dbshell -h command it’ll give you some brief help about the parameters that can be supplied. The detailed help is at django-admin and manage.py | Django documentation | Django.
Thank you so much for the detailed reply!
So I’ll go on with the basic tutorial for now.
And maybe I’ll investigate the database topic again somewhat later in more detail.