How can I temporarily disable a foreign key constraint in MySQL?

Is it possible to temporarily disable constraints in MySQL? I have two Django models, each with a foreign key to the other one. Deleting instances of a model returns an error because of the foreign key constraint: cursor.execute(“DELETE FROM myapp_item WHERE n = %s”, n) transaction.commit_unless_managed() #a foreign key constraint fails here cursor.execute(“DELETE FROM myapp_style … Read more

Is there a list of Pytz Timezones?

I would like to know what are all the possible values for the timezone argument in the Python library pytz. How to do it? 10 s 10 You can list all the available timezones with pytz.all_timezones: In [40]: import pytz In [41]: pytz.all_timezones Out[42]: [‘Africa/Abidjan’, ‘Africa/Accra’, ‘Africa/Addis_Ababa’, …] There is also pytz.common_timezones: In [45]: len(pytz.common_timezones) … Read more

What is the difference between null=True and blank=True in Django?

Want to improve this post? Provide detailed answers to this question, including citations and an explanation of why your answer is correct. without enough detail may be edited or deleted. When we add a database field in django we generally write: models.CharField(max_length=100, null=True, blank=True) The same is done with ForeignKey, DecimalField etc. What is the … Read more