فهرست منبع

Removed support for initial_data fixtures per deprecation timeline.

Tim Graham 10 سال پیش
والد
کامیت
67235fd4ef

+ 1 - 16
django/core/management/commands/flush.py

@@ -5,7 +5,6 @@ from importlib import import_module
 
 from django.apps import apps
 from django.db import connections, router, transaction, DEFAULT_DB_ALIAS
-from django.core.management import call_command
 from django.core.management.base import BaseCommand, CommandError
 from django.core.management.color import no_style
 from django.core.management.sql import sql_flush, emit_post_migrate_signal
@@ -15,8 +14,7 @@ from django.utils import six
 
 class Command(BaseCommand):
     help = ('Removes ALL DATA from the database, including data added during '
-           'migrations. Unmigrated apps will also have their initial_data '
-           'fixture reloaded. Does not achieve a "fresh install" state.')
+           'migrations. Does not achieve a "fresh install" state.')
 
     def add_arguments(self, parser):
         parser.add_argument('--noinput', action='store_false', dest='interactive', default=True,
@@ -24,9 +22,6 @@ class Command(BaseCommand):
         parser.add_argument('--database', action='store', dest='database',
             default=DEFAULT_DB_ALIAS,
             help='Nominates a database to flush. Defaults to the "default" database.')
-        parser.add_argument('--no-initial-data', action='store_false',
-            dest='load_initial_data', default=True,
-            help='Tells Django not to load any initial data after database synchronization.')
 
     def handle(self, **options):
         database = options.get('database')
@@ -82,16 +77,6 @@ Are you sure you want to do this?
 
             if not inhibit_post_migrate:
                 self.emit_post_migrate(verbosity, interactive, database)
-
-            # Reinstall the initial_data fixture.
-            if options.get('load_initial_data'):
-                # Reinstall the initial_data fixture for apps without migrations.
-                from django.db.migrations.executor import MigrationExecutor
-                executor = MigrationExecutor(connection)
-                app_options = options.copy()
-                for app_label in executor.loader.unmigrated_apps:
-                    app_options['app_label'] = app_label
-                    call_command('loaddata', 'initial_data', **app_options)
         else:
             self.stdout.write("Flush cancelled.\n")
 

+ 1 - 7
django/core/management/commands/loaddata.py

@@ -18,7 +18,6 @@ from django.utils import lru_cache
 from django.utils.encoding import force_text
 from django.utils.functional import cached_property
 from django.utils._os import upath
-from django.utils.deprecation import RemovedInDjango19Warning
 from itertools import product
 
 try:
@@ -218,14 +217,9 @@ class Command(BaseCommand):
                     (fixture_name, humanize(fixture_dir)))
             fixture_files.extend(fixture_files_in_dir)
 
-        if fixture_name != 'initial_data' and not fixture_files:
+        if not fixture_files:
             # Warning kept for backwards-compatibility; why not an exception?
             warnings.warn("No fixture named '%s' found." % fixture_name)
-        elif fixture_name == 'initial_data' and fixture_files:
-            warnings.warn(
-                'initial_data fixtures are deprecated. Use data migrations instead.',
-                RemovedInDjango19Warning
-            )
 
         return fixture_files
 

+ 0 - 12
django/core/management/commands/migrate.py

@@ -35,8 +35,6 @@ class Command(BaseCommand):
         )
         parser.add_argument('--noinput', action='store_false', dest='interactive', default=True,
             help='Tells Django to NOT prompt the user for input of any kind.')
-        parser.add_argument('--no-initial-data', action='store_false', dest='load_initial_data', default=True,
-            help='Tells Django not to load any initial data after database synchronization.')
         parser.add_argument('--database', action='store', dest='database',
             default=DEFAULT_DB_ALIAS, help='Nominates a database to synchronize. '
                 'Defaults to the "default" database.')
@@ -50,7 +48,6 @@ class Command(BaseCommand):
         self.verbosity = options.get('verbosity')
         self.interactive = options.get('interactive')
         self.show_traceback = options.get('traceback')
-        self.load_initial_data = options.get('load_initial_data')
 
         # Import the 'management' module within each installed app, to register
         # dispatcher events.
@@ -339,13 +336,4 @@ class Command(BaseCommand):
         finally:
             cursor.close()
 
-        # Load initial_data fixtures (unless that has been disabled)
-        if self.load_initial_data:
-            for app_label in app_labels:
-                call_command(
-                    'loaddata', 'initial_data', verbosity=self.verbosity,
-                    database=connection.alias, app_label=app_label,
-                    hide_empty=True,
-                )
-
         return created_models

+ 0 - 15
docs/howto/initial-data.txt

@@ -76,21 +76,6 @@ from the fixture and re-loaded into the database. Note this means that if you
 change one of the rows created by a fixture and then run :djadmin:`loaddata`
 again, you'll wipe out any changes you've made.
 
-Automatically loading initial data fixtures
--------------------------------------------
-
-.. deprecated:: 1.7
-
-    If an application uses migrations, there is no automatic loading of
-    fixtures. Since migrations will be required for applications in Django 1.9,
-    this behavior is considered deprecated. If you want to load initial data
-    for an app, consider doing it in a :ref:`data migration <data-migrations>`.
-
-If you create a fixture named ``initial_data.[xml/yaml/json]``, that fixture will
-be loaded every time you run :djadmin:`migrate`. This is extremely convenient,
-but be careful: remember that the data will be refreshed *every time* you run
-:djadmin:`migrate`. So don't use ``initial_data`` for data you'll want to edit.
-
 Where Django finds fixture files
 --------------------------------
 

+ 0 - 6
docs/ref/django-admin.txt

@@ -341,12 +341,6 @@ prompts.
 The :djadminopt:`--database` option may be used to specify the database
 to flush.
 
-``--no-initial-data``
-~~~~~~~~~~~~~~~~~~~~~
-
-Use ``--no-initial-data`` to avoid loading the initial_data fixture.
-
-
 inspectdb
 ---------
 

+ 0 - 5
docs/topics/testing/overview.txt

@@ -260,9 +260,6 @@ The initial serialization is usually very quick, but if you wish to exclude
 some apps from this process (and speed up test runs slightly), you may add
 those apps to :setting:`TEST_NON_SERIALIZED_APPS`.
 
-Apps without migrations are not affected; ``initial_data`` fixtures are
-reloaded as usual.
-
 Other test conditions
 ---------------------
 
@@ -288,8 +285,6 @@ prepares itself. You can control the level of detail of these messages with the
     Creating test database...
     Creating table myapp_animal
     Creating table myapp_mineral
-    Loading 'initial_data' fixtures...
-    No fixtures found.
 
 This tells you that the test runner is creating a test database, as described
 in the previous section.

+ 0 - 12
docs/topics/testing/tools.txt

@@ -984,18 +984,6 @@ The most straightforward way of creating a fixture is to use the
 already have some data in your database. See the :djadmin:`dumpdata
 documentation<dumpdata>` for more details.
 
-.. note::
-
-    If you've ever run :djadmin:`manage.py migrate<migrate>`, you've
-    already used a fixture without even knowing it! When you call
-    :djadmin:`migrate` in the database for the first time, Django
-    installs a fixture called ``initial_data``. This gives you a way
-    of populating a new database with any initial data, such as a
-    default set of categories.
-
-    Fixtures with other names can always be installed manually using
-    the :djadmin:`manage.py loaddata<loaddata>` command.
-
 .. admonition:: Initial SQL data and testing
 
     Django provides a second way to insert initial data into models --

+ 0 - 9
tests/fixtures/fixtures/initial_data.json

@@ -1,9 +0,0 @@
-[
-    {
-        "pk": "10",
-        "model": "fixtures.book",
-        "fields": {
-            "name": "Achieving self-awareness of Python programs"
-        }
-    }
-]

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 7 - 19
tests/fixtures/tests.py


+ 0 - 0
tests/fixtures_migration/__init__.py


+ 0 - 9
tests/fixtures_migration/fixtures/initial_data.json

@@ -1,9 +0,0 @@
-[
-    {
-        "pk": "10",
-        "model": "fixtures_migration.book",
-        "fields": {
-            "name": "Achieving self-awareness of Python programs"
-        }
-    }
-]

+ 0 - 16
tests/fixtures_migration/migrations/0001_initial.py

@@ -1,16 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    operations = [
-        migrations.CreateModel(
-            "Book",
-            [
-                ("name", models.CharField(max_length=100)),
-            ],
-        ),
-    ]

+ 0 - 0
tests/fixtures_migration/migrations/__init__.py


+ 0 - 5
tests/fixtures_migration/models.py

@@ -1,5 +0,0 @@
-from django.db import models
-
-
-class Book(models.Model):
-    name = models.CharField(max_length=100)

+ 0 - 31
tests/fixtures_migration/tests.py

@@ -1,31 +0,0 @@
-from django.test import TransactionTestCase
-from django.core import management
-
-from .models import Book
-
-
-class TestNoInitialDataLoading(TransactionTestCase):
-    """
-    Apps with migrations should ignore initial data. This test can be removed
-    in Django 1.9 when migrations become required and initial data is no longer
-    supported.
-    """
-    available_apps = ['fixtures_migration']
-
-    def test_migrate(self):
-        self.assertQuerysetEqual(Book.objects.all(), [])
-        management.call_command(
-            'migrate',
-            verbosity=0,
-        )
-        self.assertQuerysetEqual(Book.objects.all(), [])
-
-    def test_flush(self):
-        self.assertQuerysetEqual(Book.objects.all(), [])
-        management.call_command(
-            'flush',
-            verbosity=0,
-            interactive=False,
-            load_initial_data=False
-        )
-        self.assertQuerysetEqual(Book.objects.all(), [])

+ 0 - 9
tests/fixtures_model_package/fixtures/initial_data.json

@@ -1,9 +0,0 @@
-[
-    {
-        "pk": "10",
-        "model": "fixtures_model_package.book",
-        "fields": {
-            "name": "Achieving self-awareness of Python programs"
-        }
-    }
-]

+ 2 - 47
tests/fixtures_model_package/tests.py

@@ -3,11 +3,10 @@ from __future__ import unicode_literals
 import warnings
 
 from django.core import management
-from django.db import transaction
-from django.test import TestCase, TransactionTestCase
+from django.test import TestCase
 from django.utils.six import StringIO
 
-from .models import Article, Book
+from .models import Article
 
 
 class SampleTestCase(TestCase):
@@ -26,51 +25,7 @@ class SampleTestCase(TestCase):
         )
 
 
-class TestNoInitialDataLoading(TransactionTestCase):
-
-    available_apps = ['fixtures_model_package']
-
-    def test_migrate(self):
-        with transaction.atomic():
-            Book.objects.all().delete()
-
-            management.call_command(
-                'migrate',
-                verbosity=0,
-                load_initial_data=False
-            )
-            self.assertQuerysetEqual(Book.objects.all(), [])
-
-    def test_flush(self):
-        # Test presence of fixture (flush called by TransactionTestCase)
-        self.assertQuerysetEqual(
-            Book.objects.all(), [
-                'Achieving self-awareness of Python programs'
-            ],
-            lambda a: a.name
-        )
-
-        with transaction.atomic():
-            management.call_command(
-                'flush',
-                verbosity=0,
-                interactive=False,
-                load_initial_data=False
-            )
-            self.assertQuerysetEqual(Book.objects.all(), [])
-
-
 class FixtureTestCase(TestCase):
-    def test_initial_data(self):
-        "Fixtures can load initial data into models defined in packages"
-        # migrate introduces 1 initial data object from initial_data.json
-        # this behavior is deprecated and will be removed in Django 1.9
-        self.assertQuerysetEqual(
-            Book.objects.all(), [
-                'Achieving self-awareness of Python programs'
-            ],
-            lambda a: a.name
-        )
 
     def test_loaddata(self):
         "Fixtures can load data into models defined in packages"

+ 2 - 2
tests/migrate_signals/tests.py

@@ -66,7 +66,7 @@ class MigrateSignalTests(TestCase):
         signals.pre_migrate.connect(r, sender=APP_CONFIG)
         management.call_command('migrate', database=MIGRATE_DATABASE,
             verbosity=MIGRATE_VERBOSITY, interactive=MIGRATE_INTERACTIVE,
-            load_initial_data=False, stdout=six.StringIO())
+            stdout=six.StringIO())
 
         args = r.call_args
         self.assertEqual(r.call_counter, 1)
@@ -86,7 +86,7 @@ class MigrateSignalTests(TestCase):
         stdout = six.StringIO()
         management.call_command('migrate', database=MIGRATE_DATABASE,
             verbosity=MIGRATE_VERBOSITY, interactive=MIGRATE_INTERACTIVE,
-            load_initial_data=False, stdout=stdout)
+            stdout=stdout)
         args = r.call_args
         self.assertEqual(r.call_counter, 1)
         self.assertEqual(set(args), set(PRE_MIGRATE_ARGS))

+ 2 - 4
tests/multiple_database/tests.py

@@ -1778,8 +1778,7 @@ class MigrateTestCase(TestCase):
         self.assertGreater(count, 0)
 
         cts.delete()
-        management.call_command('migrate', verbosity=0, interactive=False,
-            load_initial_data=False, database='other')
+        management.call_command('migrate', verbosity=0, interactive=False, database='other')
         self.assertEqual(cts.count(), count)
 
     def test_migrate_to_other_database_with_router(self):
@@ -1788,8 +1787,7 @@ class MigrateTestCase(TestCase):
 
         cts.delete()
         with override_settings(DATABASE_ROUTERS=[SyncOnlyDefaultDatabaseRouter()]):
-            management.call_command('migrate', verbosity=0, interactive=False,
-                load_initial_data=False, database='other')
+            management.call_command('migrate', verbosity=0, interactive=False, database='other')
 
         self.assertEqual(cts.count(), 0)
 

+ 0 - 5
tests/runtests.py

@@ -239,11 +239,6 @@ def django_tests(verbosity, interactive, failfast, keepdb, reverse, test_labels,
             "use '<app_label>/sql' instead.",
             RemovedInDjango19Warning
         )
-        warnings.filterwarnings(
-            'ignore',
-            'initial_data fixtures are deprecated. Use data migrations instead.',
-            RemovedInDjango19Warning
-        )
         failures = test_runner.run_tests(
             test_labels or get_installed(), extra_tests=extra_tests)
 

+ 1 - 1
tests/swappable_models/tests.py

@@ -28,7 +28,7 @@ class SwappableModelTests(TestCase):
 
         # Re-run migrate. This will re-build the permissions and content types.
         new_io = StringIO()
-        management.call_command('migrate', load_initial_data=False, interactive=False, stdout=new_io)
+        management.call_command('migrate', interactive=False, stdout=new_io)
 
         # Check that content types and permissions exist for the swapped model,
         # but not for the swappable model.

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است