mirror of
https://github.com/django/django.git
synced 2025-08-30 15:27:40 +00:00
Fixed #31504 -- Allowed calling makemigrations without an active database connection.
This commit is contained in:
parent
952afc166c
commit
9756c33429
4 changed files with 36 additions and 4 deletions
|
@ -8,7 +8,8 @@ from unittest import mock
|
|||
from django.apps import apps
|
||||
from django.core.management import CommandError, call_command
|
||||
from django.db import (
|
||||
ConnectionHandler, DatabaseError, connection, connections, models,
|
||||
ConnectionHandler, DatabaseError, OperationalError, connection,
|
||||
connections, models,
|
||||
)
|
||||
from django.db.backends.base.schema import BaseDatabaseSchemaEditor
|
||||
from django.db.backends.utils import truncate_name
|
||||
|
@ -1555,6 +1556,19 @@ class MakeMigrationsTests(MigrationTestBase):
|
|||
with self.assertRaisesMessage(InconsistentMigrationHistory, msg):
|
||||
call_command("makemigrations")
|
||||
|
||||
def test_makemigrations_inconsistent_history_db_failure(self):
|
||||
msg = (
|
||||
"Got an error checking a consistent migration history performed "
|
||||
"for database connection 'default': could not connect to server"
|
||||
)
|
||||
with mock.patch(
|
||||
'django.db.migrations.loader.MigrationLoader.check_consistent_history',
|
||||
side_effect=OperationalError('could not connect to server'),
|
||||
):
|
||||
with self.temporary_migration_module():
|
||||
with self.assertWarnsMessage(RuntimeWarning, msg):
|
||||
call_command('makemigrations', verbosity=0)
|
||||
|
||||
@mock.patch('builtins.input', return_value='1')
|
||||
@mock.patch('django.db.migrations.questioner.sys.stdin', mock.MagicMock(encoding=sys.getdefaultencoding()))
|
||||
def test_makemigrations_auto_now_add_interactive(self, *args):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue