Opened 4 years ago
Closed 4 years ago
#32500 closed Bug (invalid)
Error "ValueError: Cannot serialize" while migrating a field containing uppercase letters
Reported by: | Timur Kadyev | Owned by: | Timur Kadyev |
---|---|---|---|
Component: | Error reporting | Version: | 3.1 |
Severity: | Normal | Keywords: | serialize |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
class FieldsType(models.Model): name = models.SlugField(max_length=32) # Records contain words in upper case, for example TYPE_COMPOSITE and ect. def get_default_type(value): return FieldsType.objects.filter(name=value).first() class Scheme(models.Mode): field_type = models.ForeignKey(FieldsType, on_delete=models.CASCADE, default=get_default_type('TYPE_COMPOSITE'))
Result:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "D:\Envs\django\lib\site-packages\django\core\management\init.py", line 401, in execute_from_command_line utility.execute()
File "D:\Envs\django\lib\site-packages\django\core\management\init.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\Envs\django\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv self.execute(*args, cmd_options)
File "D:\Envs\django\lib\site-packages\django\core\management\base.py", line 371, in execute output = self.handle(*args, options)
File "D:\Envs\django\lib\site-packages\django\core\management\base.py", line 85, in wrapped res = handle_func(*args, kwargs)
File "D:\Envs\django\lib\site-packages\django\core\management\commands\makemigrations.py", line 182, in handle self.write_migration_files(changes)
File "D:\Envs\django\lib\site-packages\django\core\management\commands\makemigrations.py", line 219, in write_migration_files migration_string = writer.as_string()
File "D:\Envs\django\lib\site-packages\django\db\migrations\writer.py", line 141, in as_string operation_string, operation_imports = OperationWriter(operation).serialize()
File "D:\Envs\django\lib\site-packages\django\db\migrations\writer.py", line 99, in serialize _write(arg_name, arg_value)
File "D:\Envs\django\lib\site-packages\django\db\migrations\writer.py", line 63, in _write arg_string, arg_imports = MigrationWriter.serialize(_arg_value)
File "D:\Envs\django\lib\site-packages\django\db\migrations\writer.py", line 271, in serialize return serializer_factory(value).serialize()
File "D:\Envs\django\lib\site-packages\django\db\migrations\serializer.py", line 199, in serialize return self.serialize_deconstructed(path, args, kwargs)
File "D:\Envs\django\lib\site-packages\django\db\migrations\serializer.py", line 86, in serialize_deconstructed arg_string, arg_imports = serializer_factory(arg).serialize()
File "D:\Envs\django\lib\site-packages\django\db\migrations\serializer.py", line 336, in serializer_factory raise ValueError(
ValueError: Cannot serialize: <FieldsType: TYPE_COMPOSITE>
There are some values Django cannot serialize into migration files.
Change History (2)
comment:1 by , 4 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:2 by , 4 years ago
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
You should use
.pk
, see #25129 and docs.