Django: Difference between revisions

From annawiki
No edit summary
Line 26: Line 26:
     manage.py
     manage.py
     mysite/
     mysite/
"The outer mysite/ root directory is a container for your project" - really? What if one had that before and performed "django-admin startproject" within that?  
"The outer mysite/ root directory is a container for your project" - really? What if one had that before (e.g. for data or the venv) and performed "django-admin startproject" within that?  


"The inner mysite/ directory is the actual Python package for your project." - the other is the container, this one "the actual Python package for your project".
"The inner mysite/ directory is the actual Python package for your project." - the other is the container, this one "the actual Python package for your project".

Revision as of 2022-06-14T22:49:10

Models

Migrations

Example 1

  • change model type e.g. Char to Integer : psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type integer: ""
  • alter field name in model ...try to delete field ...errors...
  • to fix, try to rename, remove ... delete col by hand using psql, delete migrations, recreate migration ...
  • problems: stuck in errors psycopg2.errors.DuplicateColumn: column "ccc" of relation "rrr" already exists


Example 2

  • change of field to unique can result in "DETAIL: Key (id....)=() is duplicated."

Example 3

Tutorial

https://docs.djangoproject.com/en/4.0/intro/tutorial01/

"We’ll assume you have Django installed already. " - linking to https://docs.djangoproject.com/en/4.0/intro/install/ - venv isn't mentioned, but maybe it is better to do that and not pollute the OS.

django-admin startproject mysite

Shouln't it be myproject instead of mysite, if the command is "startproject"?

The command creates:

mysite/
   manage.py
   mysite/

"The outer mysite/ root directory is a container for your project" - really? What if one had that before (e.g. for data or the venv) and performed "django-admin startproject" within that?

"The inner mysite/ directory is the actual Python package for your project." - the other is the container, this one "the actual Python package for your project".


"June 01, 2022 - 15:50:53" - why this weird data format? How about ISO 8601?

Creating the Polls app
Now that your environment – a “project” – is set up, you’re set to start doing work.

Set up are: 1) a venv 2) "a container for your project" 3) "the actual Python package for your project".