SQLite databases don’t care about your using of
max_length on your models. Let’s look at an example.
Now, we’ll run some queries.
When running SQL queries using SQLite, you find that you can create records and the database will save a
CharField with attributes with bigger strings than what the
Is there any way we can fix this? Sure there is!
One way that we can validate if our model instance is correct is to run a method called
So, what we can do is override our
save() method so that we can validate our SQLite model before we save our model. Let’s take a look.
As you can see, if
self.full_clean() throws an error, our instance will print out ‘Error saving model’ and our save method will not save our record to the database.
Try this out next time you use SQLite for your database.
I hope that works for you!