Forums

mysql errors

I added a new item to my models.py file, and now I keep getting errors when I try to run the migrate command in the bash terminal It tells me that MySQLdb._exceptions.OperationalError: (1067, "Invalid default value for 'recipe_country'") Even if I remove that line from the models.py file and makemigrations, I still get the same error

If I open a console via the database, I have no privileges in that either, I have no idea what is going on here, as I simply added country flags to an empty database.

I have deleted all the databases and added a new one and still get the same issue, I am pulling my hair out here, can someone please help and guide me on this as all the fixes on the internet do not work

Here is the errors in the bash terminal

(recipe-page-env) 21:08 ~/Heidi_recipe_page (main)$ python manage.py migrate System check identified some issues: WARNINGS: ?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default' HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL, such as data truncation upon insertion, by escalating warnings into errors. It is strongly recommended you activate it. See: https ://docs.djangoproject.com/en/4.0/ref/databases/#mysql-sql-mode Operations to perform: Apply all migrations: accounts, admin, auth, contenttypes, recipes_app, sessions Running migrations: Applying recipes_app.0015_recipe_recipe_country...Traceback (most recent call last): File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 75, in execute return self.cursor.execute(query, args) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute res = self._query(query) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query db.query(q) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/MySQLdb/connections.py", line 254, in query _mysql.connection.query(self, query) MySQLdb._exceptions.OperationalError: (1067, "Invalid default value for 'recipe_country'") The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/home/tonydav43/Heidi_recipe_page/manage.py", line 22, in <module> main() File "/home/tonydav43/Heidi_recipe_page/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/core/management/init.py", line 446, in execute_from_command_line utility.execute() File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/core/management/init.py", line 440, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/core/management/base.py", line 414, in run_from_argv self.execute(args, cmd_options) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/core/management/base.py", line 460, in execute output = self.handle(args, options) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/core/management/base.py", line 98, in wrapped res = handle_func(*args, kwargs) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 290, in handle post_migrate_state = executor.migrate( File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/migrations/executor.py", line 131, in migrate state = self._migrate_all_forwards( File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/migrations/executor.py", line 163, in _migrate_all_forwards state = self.apply_migration( File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/migrations/executor.py", line 248, in apply_migration state = migration.apply(state, schema_editor) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/migrations/migration.py", line 131, in apply operation.database_forwards( File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/migrations/operations/fields.py", line 108, in database_forwards schema_editor.add_field( File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/mysql/schema.py", line 105, in add_field super().add_field(model, field) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 641, in add_field self.execute(sql, params) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/base/schema.py", line 192, in execute cursor.execute(sql, params) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/utils.py", line 67, in execute return self._execute_with_wrappers( File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/utils.py", line 80, in _execute_with_wrappers return executor(sql, params, many, context) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/utils.py", line 91, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/utils.py", line 89, in _execute return self.cursor.execute(sql, params) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 75, in execute return self.cursor.execute(query, args) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/MySQLdb/cursors.py", line 206, in execute res = self._query(query) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/MySQLdb/cursors.py", line 319, in _query db.query(q) File "/home/tonydav43/.virtualenvs/recipe-page-env/lib/python3.9/site-packages/MySQLdb/connections.py", line 254, in query _mysql.connection.query(self, query) django.db.utils.OperationalError: (1067, "Invalid default value for 'recipe_country'")

And in the database console

mysql> FLUSH QUERY CACHE; ERROR 1227 (42000): Access denied; you need (at least one of) the RELOAD privilege(s) for this operation

Removing the line from models.py does not remove the migration that is actually causing the problem. If you want to get rid of that, I would suggest deleting all the migrations for the app that has the problem and then re-running makemigrations.

Thanks, will give it a go but still getting other errors appear, but they are not present if I run the code via my local machine, which tells me it has to be a mysql error somewhere, for example I have my .env file in the same location as my manage.py file, but I cannot link to it, I have to enter the raw data into the settings.py file to get it to work ???????

See https://help.pythonanywhere.com/pages/environment-variables-for-web-apps/ about using environment variables in web apps and using .env files in bash consoles.

Managed to get it sorted, ended up deleting databases, migrations etc and added and tested until I had it all working, but thanks for your help and advice, much appreciated