title: SqlAlchemy mysql millisecond or microsecond precision
body: <p>I've been venturing down the odyssey of trying to get fractional time resolution working properly in my database. I use the python method <code>datetime.now()</code> in order to create date objects. I then store these objects in a field which is mapped to a <code>COLUMN(DATETIME(9))</code> which is from SqlAlchemy's library. Originally, I was getting an error that my data was being truncated. This is because I was using mysql 5.5. I have since updated to 5.6.19 and no longer get the data truncated error.</p>
  
  <p>However, the database still does not actually contain fractional time entries. For example, here is the value from when the datetime.now() object is instantiated:</p>
  
  <pre><code>2015-04-17 16:31:12.804444
  </code></pre>
  
  <p>The above is exactly what I would expect. The object in memory has microsecond resolution. Now, after it saves this to the mysql database, I see the following value if I open the mysql command line client and return the row using a select statement:</p>
  
  <pre><code>2015-04-17 16:31:13
  </code></pre>
  
  <p>Obviously, the value is being rounded to the nearest second. This is bad, and I have no idea what is causing it!</p>
  
  <p>In case it is relevant, I'm using mysql-connector-python==2.0.3</p>
  
  <p>UPDATE:
  I also tried using <code>COLUMN(DATETIME(6))</code>, but got the same behavior.</p>
  
  <p>I am below including the model, in case that information is relevant:</p>
  
  <pre><code>class User(Base):
          __tablename__ = 'Users'
  
          uid = Column(INT, primary_key=True, autoincrement=True)
          dateCreated = Column(DATETIME(6))
  
          def __init__(self, *args, **kwargs):
                  super(user, self).__init__(*args, **kwargs)
                  self.dateCreated = datetime.now()
  </code></pre>
  
  <p>UPDATE:
  Pedro's suggestion wasn't the problem, though it definitely helped me make progress, so big thanks. I tried stepping through code in the sql connector until I got to the mysql insert statement. The statement does indeed contain the fractional time value. However, when executed, the value is rounded. When I did a describe on the table, I noticed that the datetime type is just that, <code>datetime</code> when it should really be <code>datetime(6)</code>. </p>
  
  <p>I'm generating the database itself using the SA model,which explicitly declares <code>Column(DATETIME(6))</code> , and <code>Base.metadata.create_all(self.db, checkfirst=True)</code> , so I don't understand why the (6) isn't ending up in the actual table structure. I think I'll figure it out shortly though, and I'll post an update when I do.</p>
  
  <p>UPDATE:
  The constructor to DATETIME does not accept field length specification. It only takes an argument for timezones. It isn't clear to me how to specify the length of a datetime field, since for types like varchar one would just pass it in to the constructor. The dive continues.</p>