How do I write this Django model in SQL?
I want to create a new column. How do I write this in SQL?
class mytable(models开发者_JAVA技巧.Model):
created_at = models.DateTimeField(auto_now_add=True)
If you don't want to use South to manage this automatically - which is highly recommended, by the way - you can easily see what SQL you need by running ./manage.py sqlall <appname>
. This will show you all the SQL to create the models in your app, so you can find the definition of your new field there.
ALTER TABLE mytable
ADD created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
精彩评论