Skip to content

make SchemaEditor.create_model() raise DatabaseError if collection exists #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
many_to_many
many_to_one
many_to_one_null
migrations.test_operations
migrations
model_fields
model_forms
mutually_referential
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ from the new application's `apps.py` file.
- You can study the skipped tests in `DatabaseFeatures.django_test_skips` for
more details on known issues.

- Due to the lack of ability to introspect MongoDB collection schema,
`migrate --fake-initial` isn't supported.

## Troubleshooting

TODO
19 changes: 19 additions & 0 deletions django_mongodb/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ def django_test_expected_failures(self):
"expressions.tests.BasicExpressionsTests.test_annotate_values_filter",
"expressions.tests.BasicExpressionsTests.test_filtering_on_rawsql_that_is_boolean",
"expressions.tests.BasicExpressionsTests.test_order_by_multiline_sql",
"migrations.test_commands.MigrateTests.test_migrate_plan",
"migrations.test_multidb.MultiDBOperationTests.test_run_sql_migrate_foo_router_with_hints",
"migrations.test_operations.OperationTests.test_run_sql",
"migrations.test_operations.OperationTests.test_run_sql_params",
"migrations.test_operations.OperationTests.test_separate_database_and_state",
Expand Down Expand Up @@ -667,8 +669,25 @@ def django_test_expected_failures(self):
},
"transaction.atomic() is not supported.": {
"backends.base.test_base.DatabaseWrapperLoggingTests",
"migrations.test_executor.ExecutorTests.test_atomic_operation_in_non_atomic_migration",
"migrations.test_operations.OperationTests.test_run_python_atomic",
},
"migrate --fake-initial is not supported.": {
"migrations.test_commands.MigrateTests.test_migrate_fake_initial",
"migrations.test_commands.MigrateTests.test_migrate_fake_split_initial",
"migrations.test_executor.ExecutorTests.test_soft_apply",
},
"SchemaEditor doesn't log or collect queries.": {
# https://github.com/mongodb-labs/django-mongodb/issues/141
"migrations.test_commands.MigrateTests.test_migrate_syncdb_app_label",
"migrations.test_commands.MigrateTests.test_migrate_syncdb_deferred_sql_executed_with_schemaeditor",
"migrations.test_commands.MigrateTests.test_sqlmigrate_backwards",
"migrations.test_commands.MigrateTests.test_sqlmigrate_for_non_atomic_migration",
"migrations.test_commands.MigrateTests.test_sqlmigrate_for_non_transactional_databases",
"migrations.test_commands.MigrateTests.test_sqlmigrate_forwards",
"migrations.test_commands.MigrateTests.test_sqlmigrate_replaced_migration",
"migrations.test_commands.MigrateTests.test_sqlmigrate_squashed_migration",
},
}

@cached_property
Expand Down
3 changes: 3 additions & 0 deletions django_mongodb/schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from django.db.backends.base.schema import BaseDatabaseSchemaEditor

from .query import wrap_database_errors


class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
@wrap_database_errors
def create_model(self, model):
self.connection.database.create_collection(model._meta.db_table)
# Make implicit M2M tables.
Expand Down