I've posted this question in stackoverflow at http://stackoverflow.com/questions/34636107/error-while-loading-data-from-fixture. The solution was posted by one Alasdair. For reference, his answer is pasted below ...
" The natural_key <https://docs.djangoproject.com/en/dev/topics/serialization/#serialization-of-natural-keys> method should return a tuple, not a string. def natural_key(self): return (self.name,) If natural_key is a string "Andaman and Nicobar" instead of a tuple ('Andaman and Nicobar',) then *natural_key will unpack each of the 19 characters in the string as a separate argument. Along with self, that gives you 20 arguments from your error message. " On Wednesday, 6 January 2016 19:59:09 UTC+5:30, Parijatha Kumar Pasupuleti wrote: > > Hai ! > > I have the following model and manager. > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > *class StateManager(models.Manager): def get_by_natural_key(self, > name): return self.get(name=name)class State(models.Model): class > Meta: verbose_name = "State" verbose_name_plural = > "States" permissions = ( ('access_state', 'Can access > States'), ) COUNTRIES = ( ('India', 'India'), > ('USA', 'USA'), ('Thailand', 'Thailand'), ) # Managers > objects = StateManager() # Database fields name = > models.CharField( 'Name', max_length=100, > unique=True, help_text=''' 100 chars max ''' ) > code = models.CharField( 'Code', max_length=10, > unique=True, help_text=''' 10 chars max ''', > null=True, blank=True ) country = models.CharField( > max_length=50, default="India", choices=COUNTRIES, > blank=False, null=False ) def __str__(self): return > self.name <http://self.name> def natural_key(self): return > self.name <http://self.name>* > > -------------------------------------------------------------------------------------- > > My fixture file is given below .... > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > *[{ "model": "parties.state", "fields": { "name": "Andaman > and Nicobar", "code": "AN", "country": "India" }},{ > "model": "parties.state", "fields": { "name": "Andhra > Pradesh", "code": "AP", "country": "India" }},{ > "model": "parties.state", "fields": { "name": "Arunachal > Pradesh", "code": "AR", "country": "India" }},{ > "model": "parties.state", "fields": { "name": "Assam", > "code": "AS", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Bihar", "code": > "BR", "country": "India" }},{ "model": "parties.state", > "fields": { "name": "Chandigarh", "code": "CH", > "country": "India" }},{ "model": "parties.state", "fields": > { "name": "Chhattisgarh", "code": "CG", "country": > "India" }},{ "model": "parties.state", "fields": { "name": > "Dadra and Nagar Haveli", "code": "DN", "country": "India" > }},{ "model": "parties.state", "fields": { "name": "Daman and > Diu", "code": "DD", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Delhi", "code": > "DL", "country": "India" }},{ "model": "parties.state", > "fields": { "name": "Goa", "code": "GA", "country": > "India" }},{ "model": "parties.state", "fields": { "name": > "Gujarat", "code": "GJ", "country": "India" }},{ > "model": "parties.state", "fields": { "name": "Haryana", > "code": "HR", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Himachal Pradesh", > "code": "HP", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Jammu and Kashmir", > "code": "JK", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Jharkhand", "code": > "JH", "country": "India" }},{ "model": "parties.state", > "fields": { "name": "Karnataka", "code": "KA", > "country": "India" }},{ "model": "parties.state", "fields": > { "name": "Kerala", "code": "KL", "country": > "India" }},{ "model": "parties.state", "fields": { "name": > "Lakshdweep", "code": "LD", "country": "India" }},{ > "model": "parties.state", "fields": { "name": "Madhya > Pradesh", "code": "MP", "country": "India" }},{ > "model": "parties.state", "fields": { "name": > "Maharashtra", "code": "MH", "country": "India" }},{ > "model": "parties.state", "fields": { "name": "Manipur", > "code": "MN", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Meghalaya", "code": > "ML", "country": "India" }},{ "model": "parties.state", > "fields": { "name": "Mizoram", "code": "MZ", > "country": "India" }},{ "model": "parties.state", "fields": > { "name": "Nagaland", "code": "NL", "country": > "India" }},{ "model": "parties.state", "fields": { "name": > "Odisha (Orissa)", "code": "OD", "country": "India" > }},{ "model": "parties.state", "fields": { "name": "Puducherry > (Pondicherry)", "code": "PY", "country": "India" }},{ > "model": "parties.state", "fields": { "name": "Punjab", > "code": "PB", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Rajasthan", "code": > "RJ", "country": "India" }},{ "model": "parties.state", > "fields": { "name": "Sikkim", "code": "SK", "country": > "India" }},{ "model": "parties.state", "fields": { "name": > "Tamil Nadu", "code": "TN", "country": "India" }},{ > "model": "parties.state", "fields": { "name": "Tripura", > "code": "TR", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Uttar Pradesh", > "code": "UP", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Uttarakhand", > "code": "UK", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "West Bengal", > "code": "WB", "country": "India" }},{ "model": > "parties.state", "fields": { "name": "Telangana", "code": > "TL", "country": "India" }}]* > > > ------------------------------------------------------------------------------------------------------------------- > > > I've earlier dumped the data to a fixture file. But when I am trying to > load the fixture now, I am getting the following error ... > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > *Traceback (most recent call last): File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/serializers/json.py", > > line 79, in Deserializer for obj in PythonDeserializer(objects, > **options): File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/serializers/python.py", > > line 157, in Deserializer obj = base.build_instance(Model, data, db) > File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/serializers/base.py", > > line 195, in build_instance obj.pk <http://obj.pk> = > Model._default_manager.db_manager(db).get_by_natural_key(*natural_key).pkTypeError: > > get_by_natural_key() takes 2 positional arguments but 20 were givenDuring > handling of the above exception, another exception occurred:Traceback (most > recent call last): File "manage.py", line 10, in <module> > execute_from_command_line(sys.argv) File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/management/__init__.py", > > line 354, in execute_from_command_line utility.execute() File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/management/__init__.py", > > line 346, in execute > self.fetch_command(subcommand).run_from_argv(self.argv) File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/management/base.py", > > line 394, in run_from_argv self.execute(*args, **cmd_options) File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/management/base.py", > > line 445, in execute output = self.handle(*args, **options) File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/management/commands/loaddata.py", > > line 60, in handle self.loaddata(fixture_labels) File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/management/commands/loaddata.py", > > line 100, in loaddata self.load_label(fixture_label) File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/management/commands/loaddata.py", > > line 151, in load_label for obj in objects: File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/serializers/json.py", > > line 85, in Deserializer six.reraise(DeserializationError, > DeserializationError(e), sys.exc_info()[2]) File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/utils/six.py", > > line 685, in reraise raise value.with_traceback(tb) File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/serializers/json.py", > > line 79, in Deserializer for obj in PythonDeserializer(objects, > **options): File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/serializers/python.py", > > line 157, in Deserializer obj = base.build_instance(Model, data, db) > File > "/home/parijath/Projects/virtualenv/django18/lib/python3.4/site-packages/django/core/serializers/base.py", > > line 195, in build_instance obj.pk <http://obj.pk> = > Model._default_manager.db_manager(db).get_by_natural_key(*natural_key).pkdjango.core.serializers.base.DeserializationError: > > Problem installing fixture > '/home/parijath/Projects/django_projects/webportal18_multipleapps/parties/fixtures/states.json': > > get_by_natural_key() takes 2 positional arguments but 20 were > given-------------------------------------------------------------------------*Pl > > help. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/2f9425cc-d8c8-41ba-9162-05139bdd4f64%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.