Adding Data: If you want to automatically add a date and time in a field only when adding an object for the first time in a Django App, set the auto_now_add=True
.
...
datefield = models.DateTimeField(auto_now_add=True, auto_now=False)
...
Updating Data: If you want to add date and time only when the object is being edited, set auto_now=True
...
datefield = models.DateTimeField(auto_now_add=False, auto_now=True)
...
If you want to add date and time while adding or updating data, set both auto_now_add=True
and auto_now=True
...
datefield = models.DateTimeField(auto_now_add=True, auto_now=True)
...
If you want to only user’s of the application to choose the date and time, then set both auto_not_add=False
and auto_now=False
...
datefield = models.DateTimeField(auto_now_add=False, auto_now=False)
...
OperationalError at /add_items/
database is locked
Request Method: POST
Request URL: http://127.0.0.1:8000/add_items/
Django Version: 2.2.7
Exception Type: OperationalError
Exception Value:
database is locked
please help me out to solve the above error,thank you
Hi Afreen, Please check out this solution: https://stackoverflow.com/questions/3172929/operationalerror-database-is-locked
IntegrityError at /add_items/
NOT NULL constraint failed: stockmgmt_stock.date
Request Method: POST
Request URL: http://localhost:8000/add_items/
Django Version: 3.1.3
Exception Type: IntegrityError
I couldn’t add items.please help me i fed up with this since yesterday
Exception Value:
NOT NULL constraint failed: stockmgmt_stock.date
This is usually a database problem. If you are in a test environment, you might wanna recreate the tables
no such column: stockmgmt_stock.timestamp
Request Method: GET
Request URL: http://127.0.0.1:8000/list_items/
Django Version: 3.1.4
Exception Type: OperationalError
Exception Value:
no such column: stockmgmt_stock.timestamp
Exception Location: C:\youtube\venv\lib\site-packages\django\db\backends\sqlite3\base.py, line 413, in execute
Python Executable: C:\youtube\venv\Scripts\python.exe
Python Version: 3.9.0
Python Path:
[‘C:\\youtube\\venv\\src’,
‘C:\\Users\\AW\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip’,
‘C:\\Users\\AW\\AppData\\Local\\Programs\\Python\\Python39\\DLLs’,
‘C:\\Users\\AW\\AppData\\Local\\Programs\\Python\\Python39\\lib’,
‘C:\\Users\\AW\\AppData\\Local\\Programs\\Python\\Python39’,
‘C:\\youtube\\venv’,
‘C:\\youtube\\venv\\lib\\site-packages’]
Server time: Tue, 29 Dec 2020 03:19:59 +0000
solve this issue by adding another column and the stock time stamp column appeared now
Great job
COUNT
CATEGORY
ITEM NAME
QUANTITY IN STORE
TIMESTAMP
LAST UPDATED
DELETE
{% for instance in queryset %}
{{forloop.counter}}
{{instance.category}}
{{instance.item_name}}
{{instance.quantity}}
{{instance.last_updated}}
{{instance.timestamp}}
{% endfor %}
where to add column ?
I am not too sure what you want. Can you explain further
where did u create another column
I don’t understand
I AM GETTING SAME PROBLEM DON’T HOW TO RESOLVE THAT.. CAN YOU PLEASE HELP ME BOB
Glad you fixed that
I’m getting this error:
no such column: stockmgmgt_stock.timestamp
Please check the spelling of your database and table
I am not getting the exact time when i saved or updated data
What are you getting
TypeError at /add_items/
unsupported operand type(s) for +: ‘Category’ and ‘str’
Request Method: POST
Request URL: http://localhost:8000/add_items/
Django Version: 3.2.3
Exception Type: TypeError
Exception Value:
unsupported operand type(s) for +: ‘Category’ and ‘str’
Exception Location: C:\youtube\venv\src\stockmgmt\forms.py, line 16, in clean_category
Python Executable: C:\youtube\venv\Scripts\python.exe
Python Version: 3.9.5
Python Path:
[‘C:\\youtube\\venv\\src’,
‘C:\\Program Files\\Python39\\python39.zip’,
‘C:\\Program Files\\Python39\\DLLs’,
‘C:\\Program Files\\Python39\\lib’,
‘C:\\Program Files\\Python39’,
‘C:\\youtube\\venv’,
‘C:\\youtube\\venv\\lib\\site-packages’]
Server time: Wed, 09 Jun 2021 11:15:34 +0000
I AM GETTING THIS ERROR WHENEVER GOING NEW ITEM IN MY EXISTING CATEGORY