Why does django check if .DATABASE_NAME db parameters really exist to run test systems?

I will often run test files for my django project. Except for one. On that beautiful day, it seemed to me that the django actually checks the settings.DATABASE_NAME db for the actual existence when the test files are run. Why is this so. All I thought was that the django would accept settings.DATABASE_NAME and create a test db named 'test_' + settings.DATABASE_NAME. It also checks if the database with name = settings.DATABASE_NAME, actually exists or not (to create a db test)? Ideally, you should only check the name but not the actual existence of db correctly?

I looked at the django source code and found out that the “connection” that is used to create testdb is actually created using the DATABASE settings. All this should be concerned about the values ​​of the settings, and not their actual existence. Correctly?

+3
source share
1 answer

... , . , Django , , DATABASE_NAME , , . ( ) DATABASE_NAME, ; , , , .

, django , .DATABASE_NAME, .

, :

  • - Django ,
  • - create_test_db, . cursor = self.connection.cursor(), , , , , , .
  • , , CREATE DATABASE .
  • , , , , settings.DATABASE_NAME test_database_name
  • . connection.cursor() ,
  • destroy_test_db, .

, django.db.backends.creation. _create_test_db.

, Django db-by-db, DB , . create_test_db backend, , .

+3

Source: https://habr.com/ru/post/1704296/


All Articles