Commit Graph

764 Commits

Author SHA1 Message Date
Hasan Ramezani 7c18b22e2f Fixed #32256 -- Fixed migration optimization crash when swapping field names.
This disables optimization of RenameField operation when an old field
name is referenced in subsequent operations.

Co-authored-by: InvalidInterrupt <InvalidInterrupt@users.noreply.github.com>
2021-02-19 11:19:01 +01:00
Daniel Ebrahimian 3f8979e37b Fixed #32350 -- Fixed showmigrations crash for applied squashed migrations.
Thanks Simon Charette for reviews.
2021-02-04 21:17:26 +01:00
Simon Charette f23b05696e Fixed #32395 -- Allowed capturing stdout of migration signals. 2021-02-04 11:19:49 +01:00
Simon Charette 42e8cf47c7 Fixed #32369 -- Fixed adding check constraints with pattern lookups and expressions as rhs.
This disables interpolation of constraint creation statements. Since
Constraint.create_sql interpolates its parameters instead of deferring
this responsibility to the backend connection it must disable
connection level parameters interpolation.
2021-01-26 06:41:57 +01:00
Simon Charette 0c42cdf0d2 Fixed #32374 -- Stopped recording migration application before deferred SQL.
Migrations cannot be recorded in the same transaction as its associated
DDL operations when some of it is deferred until the schema editor
context exits.

Regression in c86a3d80a2.
2021-01-21 07:03:35 +01:00
Simon Charette 533a583578 Refs #29721 -- Simplified migration used to test atomic recording.
This makes sure atomic recording of migration application is used when
the schema editor doesn't defer any statement.
2021-01-21 06:50:23 +01:00
Hannes Ljungberg 83fcfc9ec8 Fixed #26167 -- Added support for functional indexes.
Thanks Simon Charette, Mads Jensen, and Mariusz Felisiak for reviews.

Co-authored-by: Markus Holtermann <info@markusholtermann.eu>
2021-01-13 11:47:50 +01:00
Hasan Ramezani a2e3f95b09 Fixed #31413 -- Fixed isolation of migrations.test_loader on databases that don't support transactions. 2020-12-31 08:18:51 +01:00
William Schwartz e64c1d8055 Fixed #32302 -- Allowed migrations to be loaded from regular packages with no __file__ attribute.
The migrations loader prevents the use of PEP-420 namespace packages
for holding apps' migrations modules. Previously the loader tested for
this only by checking that app.migrations.__file__ is present. This
prevented migrations' being found in frozen Python environments that
don't set __file__ on any modules. Now the loader *additionally* checks
whether app.migrations.__path__ is a list because namespace packages
use a different type for __path__. Namespace packages continue to be
forbidden, and, in fact, users of normal Python environments should
experience no change whatsoever.
2020-12-29 12:54:08 +01:00
Mariusz Felisiak ada83fd8b8
Fixed isolation of test_migrate_fake_split_initial. 2020-12-23 07:48:45 +01:00
Hasan Ramezani 8d582bf510 Fixed #32262 -- Fixed migration optimization for model creation and Meta options removal. 2020-12-18 06:57:57 +01:00
Tim Graham 84ca7b8602
Removed hardcoded pks in migrations' test_alter_order_with_respect_to. 2020-11-07 20:26:01 +01:00
Mariusz Felisiak e6b5108acc
Fixed #27417 -- Made RenameField operation a noop for field name case changes on Oracle.
Field names are always uppercased in the Oracle backend. Changing case
should be a noop to avoid database errors: "ORA-00957: duplicate column
name".
2020-09-04 20:27:23 +02:00
Koen De Wit 4c0b4720b0 Fixed #31954 -- Fixed migration optimization for MTI model creation with parent model with mixed case app label. 2020-08-28 13:35:13 +02:00
Iuri de Silvio 632ccffc49 Fixed #31826 -- Made AlterField operation a noop when adding db_column.
AlterField operation with adding a db_column is a noop if the column
name is not changed.
2020-08-14 13:13:36 +02:00
Iuri de Silvio 7f4c9222df Fixed #31825 -- Made RenameField operation a noop for fields with db_column. 2020-08-13 13:14:58 +02:00
Iuri de Silvio 58a336a674 Fixed #31831 -- Fixed migration operations ordering when adding order_with_respect_to and constraints/indexes. 2020-08-08 20:43:45 +02:00
Iuri de Silvio 366a93f174 Refs #31831 -- Added autodector test for unique/index_together on _order field. 2020-08-08 20:43:40 +02:00
Tim Graham ff55adbd0d
Reverted "Fixed #30300 -- Allowed migrations to be loaded from directories without __init__.py file."
This reverts commit 3cd3bebe89.
2020-07-22 07:04:06 +02:00
Jon Dufresne 796be5901a Fixed #31769 -- Improved default naming of merged migrations.
47 gives 60 in total (47 + 5 + 5 + 3).
2020-07-20 15:04:22 +02:00
François Freitag 04e4f80c1f Sorted conflicting migrations by names. 2020-07-10 12:18:42 +02:00
Mariusz Felisiak 62d85a2835
Fixed #31742 -- Fixed makemigrations crash on ForeignKey to an app with mixed case label.
Regression in 9e1b6b8a66.

Thanks Ignacio Santolin for the report.
2020-06-26 23:18:59 +02:00
Nick Pope 074844e947 Fixed #31529 -- Added support for serialization of pathlib.Path/PurePath and os.PathLike in migrations. 2020-06-24 11:45:34 +02:00
Jon Dufresne 6f3e3e87ab Fixed #31703 -- Made makemigrations name all initial migrations "initial".
When the MigrationAutodetector creates more than one initial migration
in a app, name all initial migrations "initial" rather than the opaque
"auto_<DATE>_<TIME>" name.

Initial migrations that have a descriptive name continue to use the
descriptive name.
2020-06-24 07:18:45 +02:00
Jon Dufresne 01195c4a83 Refs #31703 -- Added Migration.suggest_name() test for initial migration with multiple CreateModels. 2020-06-24 07:18:38 +02:00
Jon Dufresne bce180dd05 Refs #31703 -- Moved MigrationAutodetector.suggest_name() to Migration.
Allows expanding the method to inspect additional attributes of the
migration instance. For example, the Migration.initial attribute.
2020-06-24 07:01:11 +02:00
Chinmoy Chakraborty 2928019e0c Fixed #31645 -- Enhanced the migration warning for migrate commmand.
Added the list of apps with changes not reflected in migrations.
2020-06-12 10:26:06 +02:00
davidchorpash 07506a6114 Fixed #31661 -- Removed period in makemigrations history check warning. 2020-06-08 06:46:23 +02:00
Hannes Ljungberg 8c7992f658 Fixed #30913 -- Added support for covering indexes on PostgreSQL 11+. 2020-06-04 12:26:22 +02:00
Adam Johnson fa58450a9a Fixed #31468 -- Allowed specifying migration filename in Operation.
This adds also suggested filename for many built-in operations.
2020-05-28 11:42:53 +02:00
Adam Johnson 5bd585a82d Refs #31468 -- Added tests for MigrationAutodetector.suggest_name(). 2020-05-28 11:24:58 +02:00
Mariusz Felisiak 42de52affe
Fixed isolation of test_migrate_fake_initial. 2020-05-28 09:32:43 +02:00
Nan Liu 33c365781a Fixed #31416 -- Made autodetector find dependencies for MTI model creation on base fields removal.
Removing a base field must take place before adding a new inherited
model that has a field with the same name.
2020-05-26 07:26:07 +02:00
wtkm11 9756c33429 Fixed #31504 -- Allowed calling makemigrations without an active database connection. 2020-05-19 10:24:23 +02:00
Ian Foote c226c6cb32 Fixed #20581 -- Added support for deferrable unique constraints. 2020-04-30 10:43:50 +02:00
François Freitag f19bb54fb1 Added test for squashmigrations' output. 2020-04-28 06:32:43 +02:00
François Freitag 687cb38a05 Removed unnecessary capturing/hiding of stdout/stderr in various tests. 2020-04-27 08:06:12 +02:00
François Freitag a8d175c297 Disabled management commands output with verbosity 0 in test_regression_22823_unmigrated_fk_to_migrated_model. 2020-04-27 07:43:09 +02:00
François Freitag da606513db
Removed unnecessary capturing of stdout in test_makemigrations_non_interactive_not_null_addition. 2020-04-25 20:53:53 +02:00
David Wobrock 533b208775 Fixed #29224 -- Fixed removing index_together indexes if exists unique_together constraint on the same fields. 2020-04-23 12:28:51 +02:00
Simon Charette 06889d6206 Fixed #31499 -- Stored ModelState.fields into a dict.
This allows the removal of its O(n) .get_field_by_name method and many
other awkward access patterns.

While fields were initially stored in a list to preserve the initial
model definiton field ordering the auto-detector doesn't take field
ordering into account and no operations exists to reorder fields of a
model.

This makes the preservation of the field ordering completely superflous
because field reorganization after the creation of the model state
wouldn't be taken into account.
2020-04-22 07:10:00 +02:00
Simon Charette 696024fb73 Refs #31499 -- Ignored field ordering to determine ModelState equality. 2020-04-22 06:20:54 +02:00
Simon Charette 5220ca8d8a Refs #30591 -- Adjusted table rebuild for non-pk relationship on SQLite.
The existing code was only accounting for primary key changes and not
all unique key fields that can be referenced.
2020-04-21 08:37:47 +02:00
Simon Charette a548280857 Fixed #31064 -- Recreated auto-created many-to-many tables on primary key data type change on SQLite.
Both local and remote auto-created many-to-many relationships were
affected.
2020-04-21 08:37:40 +02:00
Simon Charette 2ba55b2905 Removed redundant import in tests/migrations/test_operations.py. 2020-04-21 08:37:37 +02:00
Simon Charette 8069526ce3 Made Operation.references_model/references_field require app_label.
This will allow them to drop a ton of logic to deal with null
app_label.
2020-04-09 10:08:06 +02:00
Simon Charette 25bf15c0da Refs #22608 -- Made app_label required when optimizing migrations.
This paved the way for the removal of lot of logic when app_label was
not specified.
2020-04-09 10:08:02 +02:00
Mariusz Felisiak db6933a032
Refs #30966 -- Added test for reloading related model state on non-relational changes.
Thanks Markus Holtermann for initial test.

Fixed in 1d16c5d562.
2020-04-08 10:43:38 +02:00
Simon Charette 1d16c5d562 Refs #27666 -- Ensured relationship consistency on delayed reloads.
Delayed reloads of state models broke identity based relationships
between direct and non-direct ancestors.

Basing models.Options related objects map of model labels instead of
their identity ensured relationship consistency is maintained.

Refs #30966.

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2020-04-07 09:20:46 +02:00
Gordon Pendleton d0da2820ca Fixed #31402 -- Added migrate --check option.
Command exits with non-zero status if unapplied migrations exist.
2020-03-26 20:12:39 +01:00
Adam Johnson 9e1b6b8a66 Fixed #23916 -- Allowed makemigrations to handle related model name case changes.
Made autodetector ignore related model name case changes so unnecessary
migrations are not created.
2020-03-25 10:39:34 +01:00
David Wobrock d88365708c Fixed #31318 -- Allowed sqlmigrate to inspect squashed migrations. 2020-03-09 08:42:30 +01:00
David Wobrock b88ad1d356 Refs #31318 -- Added tests for inspecting squashed migrations and ambiguous names in sqlmigrate. 2020-03-09 08:21:34 +01:00
Nick Pope 335c9c94ac Simplified imports from django.db and django.contrib.gis.db. 2020-02-04 13:20:06 +01:00
Mariusz Felisiak b423873cb7
Refs #31197 -- Added tests for combined expressions in CheckConstraint.check.
Thanks Adam Johnson for the report.

Fixed in 306b687520.
2020-01-23 10:28:36 +01:00
Matthijs Kooijman 2a2ea4ee18 Refs #31117 -- Made various tests properly handle unexpected databases aliases.
- Used selected "databases" instead of django.db.connections.
- Made routers in tests.migrations skip migrations on unexpected
  databases.
- Added DiscoverRunnerGetDatabasesTests.assertSkippedDatabases() hook
  which properly asserts messages about skipped databases.
2020-01-20 14:39:02 +01:00
Mariusz Felisiak bf77669453
Fixed #29998 -- Allowed multiple OneToOneFields to the parent model.
We assumed that any OneToOneField's in a child model must be the
parent link and raised an error when parent_link=True was not
specified. This patch allows to specify multiple OneToOneField's to
the parent model.

OneToOneField's without a custom related_name will raise fields.E304
and fields.E305 so this should warn users when they try to override
the auto-created OneToOneField.
2020-01-16 08:06:16 +01:00
John Bowen 29d8198841 Fixed #27914 -- Fixed serialization of nested classes in migrations. 2019-11-25 11:12:44 +01:00
John Bowen 8008795a38 Refs #23950 --- Moved test DeconstructibleInstances class to a module level.
DeconstructibleInstances was not importable from the asserted path.
2019-11-25 11:05:09 +01:00
Jon Dufresne e649d691f8 Removed unnecessary parentheses in various code. 2019-11-18 15:25:59 +01:00
Mariusz Felisiak 4527d5db0f
Refs #29808 -- Fixed MigrateTests.test_migrate_fake_initial_case_insensitive() crash on Oracle. 2019-11-15 21:05:42 +01:00
Hasan Ramezani 530dd193f2 Fixed #29808 -- Fixed initial migration detection when identifiers are case-insensitive.
Thanks Simon Charette for the review.
2019-11-15 09:01:30 +01:00
Nick Pope 7552de7866 Used more specific unittest assertions in tests.
* assertIsNone()/assertIsNotNone() instead of comparing to None.
* assertLess() for < comparisons.
* assertIs() for 'is' expressions.
* assertIsInstance() for isinstance() expressions.
* rounding of assertAlmostEqual() for round() expressions.
* assertIs(..., True/False) instead of comparing to True/False.
* assertIs()/assertIsNot() for ==/!= comparisons.
* assertNotEqual() for == comparisons.
* assertTrue()/assertFalse() instead of comparing to True/False.
2019-10-29 12:37:30 +01:00
Mariusz Felisiak 06d34aab7c Fixed #30870 -- Fixed showing that RunPython operations are irreversible by migrate --plan.
Thanks Hasan Ramezani for the initial patch and Kyle Dickerson for the
report.
2019-10-14 11:13:27 +02:00
Mariusz Felisiak 05186c03a3 Isolated migrations.test_commands.MigrateTests.test_migrate_plan. 2019-10-14 08:42:38 +02:00
Simon Charette 2839659b42 Fixed #30868 -- Prevented unnecessary AlterField when renaming a referenced pk.
Regression introduced by dcdd219ee1, refs #25817.

Thanks Carlos E. C. Leite for the report and Mariusz for the bisect.
2019-10-14 08:02:26 +02:00
Benjy Weinberger 3cd3bebe89 Fixed #30300 -- Allowed migrations to be loaded from directories without __init__.py file. 2019-10-10 08:31:41 +02:00
Hasan Ramezani 6452112640 Refs #27914 -- Fixed serialization of nested enum.Enum classes in migrations. 2019-10-03 08:39:30 +02:00
Hasan Ramezani d3030deaaa Refs #27914 -- Moved test enum.Enum subclasses outside of WriterTests.test_serialize_enums(). 2019-10-03 08:39:30 +02:00
Hasan Ramezani f0adf3b9b7 Fixed #30774 -- Made serialization in migrations use members names for Enums. 2019-09-30 10:28:05 +02:00
Mariusz Felisiak 937ddaff55
Refs #30591 -- Fixed too long identifier crash in migrations.test_operations on MySQL 8.0.16+. 2019-09-11 12:20:16 +02:00
Adnan Umer 241deed259 Fixed #30591 -- Fixed recreation of foreign key constraints on MySQL when altering type of referenced unique field.
Thanks Mariusz Felisiak for tests and Matthijs Kooijman for
investigation and initial patch.
2019-09-11 11:21:08 +02:00
Shai Berger 72ebe85a26 Fixed #27910 -- Added enumeration helpers for use in Field.choices.
These classes can serve as a base class for user enums, supporting
translatable human-readable names, or names automatically inferred
from the enum member name.

Additional properties make it easy to access the list of names, values
and display labels.

Thanks to the following for ideas and reviews:

Carlton Gibson, Fran Hrženjak, Ian Foote, Mariusz Felisiak, Shai Berger.

Co-authored-by: Shai Berger <shai@platonix.com>
Co-authored-by: Nick Pope <nick.pope@flightdataservices.com>
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
2019-09-04 14:42:49 +02:00
Viktor Lomakin 5931d2e96a Fixed #30691 -- Made migrations autodetector find dependencies for foreign keys altering. 2019-09-03 14:45:49 +02:00
Mads Jensen 85ac838d9e Fixed #21039 -- Added AddIndexConcurrently/RemoveIndexConcurrently operations for PostgreSQL.
Thanks to Simon Charettes for review.

Co-Authored-By: Daniel Tao <daniel.tao@gmail.com>
2019-08-21 13:10:06 +02:00
Mads Jensen b10d322c41 Moved migrations.test_operations.OperationTestBase to migrations.test_base.
Co-Authored-By: Daniel Tao <daniel.tao@gmail.com>
2019-08-19 16:06:14 +02:00
Min ho Kim 65e86948b8 Corrected several typos in string literals and test names. 2019-08-07 11:23:14 +02:00
Nick Pope 194d1dfc18 Fixed #30661 -- Added models.SmallAutoField. 2019-08-02 11:39:01 +02:00
Mariusz Felisiak 8233144ca0 Changed django.db.models.indexes.Index imports to django.db.models.Index. 2019-07-08 14:19:46 +02:00
Hasan Ramezani 5d03f2bc01 Fixed #30595 -- Added error message when no objects found to sql* management commands. 2019-07-01 13:47:54 +02:00
Jon Dufresne 42b9a23267 Fixed #30400 -- Improved typography of user facing strings.
Thanks Claude Paroz for assistance with translations.
2019-06-28 16:46:18 +02:00
can 719b746620 Fixed #30412 -- Fixed crash when adding check constraints with OR'ed condition on Oracle and SQLite. 2019-04-30 12:32:27 +02:00
Simon Charette a8b3f96f6a Fixed #30408 -- Fixed crash when adding check constraints with LIKE operator on Oracle and PostgreSQL.
The LIKE operator wildcard generated for contains, startswith, endswith and
their case-insensitive variant lookups was conflicting with parameter
interpolation on CREATE constraint statement execution.

Ideally we'd delegate parameters interpolation in DDL statements on backends
that support it but that would require backward incompatible changes to the
Index and Constraint SQL generating methods.

Thanks David Sanders for the report.
2019-04-30 07:38:22 +02:00
Florian Apolloner 2e38f2015a
Fixed #30350 -- Prevented recreation of migration for operations with a range object.
Thanks to Mariusz Felisiak for helping with the patch.
2019-04-14 12:04:48 +02:00
tschilling 7c68cea7ee Fixed #30186 -- Made showmigrations --list display the applied datetimes at verbosity 2+. 2019-03-08 08:25:38 -05:00
Tim Schilling 371ddade1e Refs #30186 -- Changed MigrationRecorder.applied_migrations() to return a dict. 2019-03-07 19:36:55 -05:00
Parth Patil acc041984f Fixed #30189 -- Removed transaction from sqlmigrate output if database doesn't use one. 2019-03-07 18:28:22 -05:00
Dan Davis 2bd8df243a Fixed #30184 -- Removed ellipsis characters from shell output strings.
Partially reverted 50b8493581 (refs #29654)
to avoid a crash when the user shell doesn't support non-ASCII characters.
2019-02-13 13:59:44 -05:00
Semen Zhydenko 255d6a26a8 Fixed spelling mistakes in comments and tests. 2019-02-11 08:55:57 -05:00
Tim Graham 7e6b214ed3 Fixed #30116 -- Dropped support for Python 3.5. 2019-01-30 10:19:48 -05:00
Paveł Tyślacki 62b8596616 Made test table cleanup in OperationTestBase more robust.
Some non-unique constraint names were added in
b69f8eb04c which resulted in failures
depending on the order in which tests were run.
2019-01-28 11:51:23 -05:00
Jon Dufresne 7e3bf2662b Removed default mode='r' argument from calls to open(). 2019-01-27 17:41:43 -05:00
Vytis Banaitis d02b2aa11e Made assertOptimizesTo() more strict in migrations tests.
A recursive deconstruction is needed because comparing deconstructed
operations doesn't check field attributes. Fixed typo in failing test.
2019-01-21 17:29:46 -05:00
Paveł Tyślacki b69f8eb04c Fixed #30062 -- Added support for unique conditional constraints. 2019-01-12 09:50:20 -05:00
can 7d3b3897c1 Refs #29738 -- Allowed registering serializers with MigrationWriter. 2019-01-11 18:13:16 -05:00
Tim Graham 8f4eee1777
Moved django.db.migrations.writer.SettingsReference to django.conf.
Reduces the possibility of circular imports.
2019-01-11 15:28:22 -05:00
Simon Charette 8c775391b7 Refs #28478 -- Deprecated TestCase's allow_database_queries and multi_db in favor of databases. 2019-01-10 19:11:21 -05:00
Dakota Hawkins 8d3147e130 Fixed #30031 -- Added --no-header option to makemigrations/squashmigrations. 2018-12-19 12:41:31 +01:00
Tim Fiedler b07273a0f7 Fixed #29987 -- Detected unmanaged model deletions. 2018-11-30 09:57:43 -05:00
Tim Graham 193c109327 Switched TestCase to SimpleTestCase where possible in Django's tests. 2018-11-27 08:58:44 -05:00