Zero date in mysql select using python
<p>I have a python script which selects some rows from a table and insert them into another table. One field has type of date and there is a problem with its data when its value is '0000-00-00'. python converts this value to None and so gives an error while inserting it into the second table.</p>

<p>How can I solve this problem? Why python converts that value to None?</p>

<p>Thank you in advance.</p>

<p>This is actually a None value in the data base, in a way. MySQL treats '0000-00-00' specially.
From <a href="http://dev.mysql.com/doc/refman/5.7/en/date-and-time-types.html" rel="nofollow">MySQL documentation</a>:</p>

<blockquote>
  <p>MySQL permits you to store a âzeroâ value of '0000-00-00' as a âdummy
  date.â This is in some cases more convenient than using NULL values,
  and uses less data and index space. To disallow '0000-00-00', enable
  the NO_ZERO_DATE mode.</p>
</blockquote>

<p>It seems that Python's MySQL library is trying to be nice to you and converts this to None.</p>

<p>When writing, it cannot guess that you wanted '0000-00-00' and uses NULL instead. You should convert it yourself. For example, this might work:</p>

<pre><code>if value_read_from_one_table is not None:
    value_written_to_the_other_table = value_read_from_one_table
else:
    value_written_to_the_other_table = '0000-00-00'
</code></pre>

python mysql date select