0

I'm having trouble trying to initialize some data.

When I run manage.py loaddata --verbosity=1 initial.json

With this as my initial.json file:

[
  {
    "model": "listen.Playlist",
    "pk": 1,
    "fields": {
      "message": "Hello There!",
      "url": "pl8675309",
      "background": "citylights.png"
    }
  }
]

And the output I get is:

File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/loaddata.py", line 64, in handle
    self.loaddata(fixture_labels)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/loaddata.py", line 104, in loaddata
    self.load_label(fixture_label)
  File "/Library/Python/2.7/site-packages/django/core/management/commands/loaddata.py", line 161, in load_label
    for obj in objects:
  File "/Library/Python/2.7/site-packages/django/core/serializers/json.py", line 86, in Deserializer
    six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
  File "/Library/Python/2.7/site-packages/django/core/serializers/json.py", line 80, in Deserializer
    for obj in PythonDeserializer(objects, **options):
  File "/Library/Python/2.7/site-packages/django/core/serializers/python.py", line 183, in Deserializer
    obj = base.build_instance(Model, data, db)
  File "/Library/Python/2.7/site-packages/django/core/serializers/base.py", line 218, in build_instance
    obj = Model(**data)
  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 556, in __init__
    super(Model, self).__init__()
django.core.serializers.base.DeserializationError: Problem installing fixture 'initial.json': __init__() takes exactly 3 arguments (1 given)

1 Answers1

0

You haven't shown a Minimal Complete Verifiable Example, so it's not feasible for us to reproduce what your code does.

I can guess that the Model subclass you've written has a custom __init__ that unexpectedly requires more arguments:

  File "/Library/Python/2.7/site-packages/django/db/models/base.py", line 556, in __init__
    super(Model, self).__init__()
django.core.serializers.base.DeserializationError: Problem installing fixture 'initial.json': __init__() takes exactly 3 arguments (1 given)

If so, you've broken the Liskov substitution Principle (one of the SOLID principles) — your subclass does not actually allow use as the parent class.

bignose
  • 30,281
  • 14
  • 77
  • 110