Reputation: 153
I have just started learning Django frame work and got stuck after getting an unexpected error as below:-(I have tried to post all information, which i find necessary to be here)
TypeError: __init__() got an unexpected keyword argument 'upload_to'
I got this error while running command python manage.py makemigrations
My project contains only one Model class Products
My Model Class:-
from django.db import models
# Create your models here.
class Products(models.Model):
name = models.CharField(max_length=25)
price = models.IntegerField()
description = models.CharField(max_length=50)
pic = models.DateTimeField(upload_to="myimages")
I am added my app in INSTALLED_APPS fields in setting.py
Full Error Track:-
Traceback (most recent call last):
File "C:\Users\Admin\PycharmProjects\ecommerceproject\manage.py", line 22, in <module>
main()
File "C:\Users\Admin\PycharmProjects\ecommerceproject\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\Admin\PycharmProjects\ecommerceproject\products\models.py", line 5, in <module>
class Products(models.Model):
File "C:\Users\Admin\PycharmProjects\ecommerceproject\products\models.py", line 9, in Products
pic = models.DateTimeField(upload_to="myimages")
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\fields\__init__.py", line 1158, in __init__
super().__init__(verbose_name, name, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'upload_to'
C:\Users\Admin\PycharmProjects\ecommerceproject>cls
C:\Users\Admin\PycharmProjects\ecommerceproject>python manage.py makemigrations
Traceback (most recent call last):
File "C:\Users\Admin\PycharmProjects\ecommerceproject\manage.py", line 22, in <module>
main()
File "C:\Users\Admin\PycharmProjects\ecommerceproject\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\management\__init__.py", line 395, in execute
django.setup()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\apps\config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\Admin\PycharmProjects\ecommerceproject\products\models.py", line 5, in <module>
class Products(models.Model):
File "C:\Users\Admin\PycharmProjects\ecommerceproject\products\models.py", line 9, in Products
pic = models.DateTimeField(upload_to="myimages")
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\fields\__init__.py", line 1158, in __init__
super().__init__(verbose_name, name, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'upload_to'
Thanks in advance. Hope to here from you soon.
Upvotes: 1
Views: 3869
Reputation: 346
It doesn't seem like DateTimeField
accepts the upload_to
keyword argument.
pic = models.DateTimeField(upload_to="myimages")
See docs.
Were you trying to use another Model Field? e.g., ImageField
, FileField
Upvotes: 2
Reputation: 571
You are getting error because of it. Try with proper field
pic = models.DateTimeField(upload_to="myimages")
Upvotes: 0