saving . . . saved Error has been deleted. Error has been hidden .
Error
Title
Question
I am getting an error  
File "/home/sandeep/my-django/mysite/blog/models.py", line 8
 (auto_now_add=True)
                         ^
SyntaxError: invalid syntax



Python-Django Creating-Django-Models 04-05 min 0-10 sec 28-08-19, 6:01 p.m. sandeepbvjniot@gmail.com

Answers:

Kindly share the complete code for models.py
29-08-19, 10:22 a.m. pravin1389

--------------------------------------------------------------------------------
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/sandeep/my-django/myapp_env/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/sandeep/my-django/myapp_env/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/sandeep/my-django/myapp_env/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/sandeep/my-django/myapp_env/lib/python3.6/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/home/sandeep/my-django/myapp_env/lib/python3.6/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 674, in exec_module
File "<frozen importlib._bootstrap_external>", line 781, in get_code
File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/sandeep/my-django/mysite/blog/models.py", line 8
(auto_now_add=True)
^
SyntaxError: invalid syntax
----------------------------------------------------------------------------
code

from django.db import models

# Create your models here.

class Blog(models.Model):
<span style="white-space:pre">\\t</span>name = models.CharField(max_length=120)
<span style="white-space:pre">\\t</span>created_on = models.DateTimeField
(auto_now_add=True)

class Article(models.Model):
<span style="white-space:pre">\\t</span>blog = models.ForeignKey(Blog,on_delete=models.CASCADE)
<span style="white-space:pre">\\t</span>created_on = models.DateTimeField
(auto_now_add=True)
<span style="white-space:pre">\\t</span>title = models.CharField(max_length=120)
<span style="white-space:pre">\\t</span>body = models.TextField()
<span style="white-space:pre">\\t</span>draft = models.BooleanField(default=False)
29-08-19, 10:31 a.m. sandeepbvjniot@gmail.com
from django.db import models

# Create your models here.

class Blog(models.Model):
<span style="white-space:pre">\t</span>name = models.CharField(max_length=120)
<span style="white-space:pre">\t</span>created_on = models.DateTimeField
(auto_now_add=True)

class Article(models.Model):
<span style="white-space:pre">\t</span>blog = models.ForeignKey(Blog,on_delete=models.CASCADE)
<span style="white-space:pre">\t</span>created_on = models.DateTimeField
(auto_now_add=True)
<span style="white-space:pre">\t</span>title = models.CharField(max_length=120)
<span style="white-space:pre">\t</span>body = models.TextField()
<span style="white-space:pre">\t</span>draft = models.BooleanField(default=False)
29-08-19, 10:34 a.m. sandeepbvjniot@gmail.com

Login to add comment


Please see following code:
-------------------------------------------------------------
from django.db import models

# Create your models here.

class Blog(models.Model):
<span style="white-space:pre">\t</span>name = models.CharField(max_length=120)
<span style="white-space:pre">\t</span>created_on = models.DateTimeField
(auto_now_add=True)

class Article(models.Model):
<span style="white-space:pre">\t</span>blog = models.ForeignKey(Blog,on_delete=models.CASCADE)
<span style="white-space:pre">\t</span>created_on = models.DateTimeField
(auto_now_add=True)
<span style="white-space:pre">\t</span>title = models.CharField(max_length=120)
<span style="white-space:pre">\t</span>body = models.TextField()
<span style="white-space:pre">\t</span>draft = models.BooleanField(default=False)
--------------------------------------------------------------------------
29-08-19, 10:35 a.m. sandeepbvjniot@gmail.com


Same error i am also getting
And my code is perfect
05-04-20, 5:45 p.m. Dharm_007


You'll are starting the line with (auto_now_add=True)
which iserror in Python.
There is an error in line continuation.
Continue to write the above code on the same line ....DateTimeFiled(auto_now_add=True)
13-05-20, 11:59 p.m. pratham920


Log-in to answer to this question.