Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在迁移脚本中的表上设置自动递增 1
ALTER TABLE Table_name AUTO_INCREMENT = 1;
是否可以在创建表期间或之后在您的数据库迁移脚本中提及这一点。
也许有更好的解决方案。否则,您可以在迁移脚本中运行原始 SQL 语句,如下所示:
ActiveRecord::Base.connection.execute("ALTER TABLE Table_name AUTO_INCREMENT = 1")