Field 'file_hash' doesn't have a default value
See original GitHub issueIssue Summary
New file_hash field in wagtailimages Image model having issue with mysql database (v5.7) when uploading images through wagtail admin.
Steps to Reproduce
- Install following version described in Technical Details
- Try to upload an image.
After looking into wagtail source it seems like, this issue lies in field definition
file_hash = models.CharField(max_length=40, blank=True, editable=False)
Possibly MySQL strict mode is throwing error as no default value has been provided for file_hash
Technical details
- Python version: 3.6
- Django version: 2.0.8
- Wagtail version: 2.1.3
- MySQL version: 5.7
Stack trace
Traceback (most recent call last):
File ".venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File ".venv/lib/python3.6/site-packages/django/db/backends/mysql/base.py", line 71, in execute
return self.cursor.execute(query, args)
File ".venv/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File ".venv/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File ".venv/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File ".venv/lib/python3.6/site-packages/MySQLdb/cursors.py", line 412, in _query
rowcount = self._do_query(q)
File ".venv/lib/python3.6/site-packages/MySQLdb/cursors.py", line 375, in _do_query
db.query(q)
File ".venv/lib/python3.6/site-packages/MySQLdb/connections.py", line 276, in query
_mysql.connection.query(self, query)
_mysql_exceptions.IntegrityError: (1364, "Field 'file_hash' doesn't have a default value")
Possible Solution
For now I have manually altered the database with a default value -
Alter table wagtailimages_image modify column file_hash varchar(40) not null default '';
Field declaration might be like following, so that either a default value is there or null is accepted
file_hash = models.CharField(max_length=40, blank=True, null=True, editable=False)
Or
file_hash = models.CharField(max_length=40, blank=True, default='', editable=False)
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Field 'id' doesn't have a default value? - Stack Overflow
I am making a database for games of cards to use in my homepage. I am using MySQL Workbench on Windows. The error...
Read more >How to Use the Get-FileHash PowerShell Cmdlet
The default value is SHA256 for all versions of PowerShell, if no other algorithm is specified. Computing the hash value of a single...
Read more >Working with AppLocker rules (Windows) - Microsoft Learn
This topic for IT professionals describes AppLocker rule types and how to work with them for your application control policies.
Read more >General error: field doesn't have a default value - Laracasts
General error: field doesn't have a default value. Here's one of the method I have in my model. Copy Code public function addUser($account, ......
Read more >What is Hashing and How Does it Work? - SentinelOne
Hashes cannot be reversed, so simply knowing the result of a file's hash from a hashing algorithm ... However, that doesn't mean hash...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Also of note, If you have upgraded to/past 2.2, and you have any custom image models you will need to run
makemigrations
to add the file hash for the model.@gasman You were right. Somehow our pipenv lock file were changed. Which led to different version of wagtail when migrating between servers.
Sorry for not checking out that. Anyway, we love wagtail.