2

I'm making a test project with python and django (for learning purpose). At some point I have to make a django app called products, then in the models.py file in the "products" app directory I have this code:

class Products (models.Model)
     title = models.TextField() 
     description = models.TextField()
     price = models.TextField()

and then after adding the new app in the settings file when I attend to make migrations as shown:

> python manage.py makemigrations 

I get is this error:

  Traceback (most recent call last):
      File "manage.py", line 15, in <module>
        execute_from_command_line(sys.argv)
      File "C:\django\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
        utility.execute()
      File "C:\django\lib\site-packages\django\core\management\__init__.py", line 347, in execute
        django.setup()
      File "C:\django\lib\site-packages\django\__init__.py", line 24, in setup
        apps.populate(settings.INSTALLED_APPS)
      File "C:\django\lib\site-packages\django\apps\registry.py", line 112, in populate
        app_config.import_models()
      File "C:\django\lib\site-packages\django\apps\config.py", line 198, in import_models
        self.models_module = import_module(models_module_name)
      File "C:\django\lib\importlib\__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
      File "<frozen importlib._bootstrap>", line 983, in _find_and_load
      File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 724, in exec_module
      File "<frozen importlib._bootstrap_external>", line 860, in get_code
      File "<frozen importlib._bootstrap_external>", line 791, in source_to_code
      File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
      File "C:\django\mystore\products\models.py", line 5
        class Products(models.Model)
                                   ^
    SyntaxError: invalid syntax

 "

and then the same error occurs whenever I try to use the manage.py file. I don't know what I've done wrong please help me fix this.

Neek
  • 7,181
  • 3
  • 37
  • 47
  • 1
    you are missing missing a `:` in `C:\django\mystore\products\models.py`. class definition should e `class A(B):` – Kevin He Feb 13 '19 at 18:23

2 Answers2

1

You're missing a colon after the class declaration.

class Products(models.Model):

Also, I would caution you on your formatting. Your field names should line up on the left. In Python, two lines that don't line up are considered different blocks of code.

dirkgroten
  • 20,112
  • 2
  • 29
  • 42
RYou
  • 46
  • 5
0

You missed a colon after you declared the class

class Products (models.Model)  #<<--- no semicolon
 title = models.TextField() 
 description = models.TextField()
 price = models.TextField()

Right code:

class Products (models.Model):  #<<---  colon
 title = models.TextField() 
 description = models.TextField()
 price = models.TextField()