我有很多PHP代码,我想将其翻译成AdonisJS。
我在这里有一个数据库表,我想用此代码迁移到Adonis。
这是PHP中的默认代码:
$schema = new \Doctrine\DBAL\Schema\Schema();
$myTable = $schema->createTable("user_comenzi");
$myTable->addColumn("id", "integer", array("unsigned" => true,"autoincrement"=>true));
$myTable->addColumn("user_id", "integer", array("unsigned" => true));
$myTable->addColumn("adresa_id", "integer", array("unsigned" => true));
$myTable->addColumn("creat", "datetime", array());
$myTable->addColumn("status", "integer", array("default"=>0));
$myTable->addColumn("comanda", "text");
$myTable->setPrimaryKey(array("id"));
//$schema->createSequence("comenzi_seq");
$platform = new \Doctrine\DBAL\Platforms\SqlitePlatform();
$queries = $schema->toSql($platform); // get queries to create this schema.
print_r($queries);
$app['db']->query($queries[0]);
在AdonisJS中应该是这样的:
class UserComenziSchema extends Schema {
up () {
this.create('user_comenzi', (table) => {
table.increments()
table.integer('user_id').unsigned()
table.integer('adresa_id').unsigned()
table.time('creat')
table.integer('status').defaultTo(0)
table.text('comanda')
table.timestamps()
})
}
down () {
this.drop('user_comenzi')
}
}
我只想看看我的代码是否错误,如果我错了,为什么?
答案 0 :(得分:0)
将table.time('creat')
更改为table.datetime('creat')
,就可以了