<p>>>>รบกวนอาจารย์ช่วยดูโค้ดให้หน่อยครับว่าผิดตรงไหนบ้างครับ.....ไม่ create table เลยครับ ทำตามอาจารย์ทุกอย่างแล้วแต่ในฐานข้อมูลไม่มีการ Create Table เลย....<span style="background-color: initial;">มือใหม่หัดเล่นครับ<<<</span></p><p><?php</p><p>use yiidbSchema;</p><p>use yiidbMigration;</p><p>class m150724_021725_create_user_profile_table extends Migration</p><p>{</p><p> public function up() {</p><p>$this->createTable('user', [</p><p> 'id' => Schema::TYPE_PK,</p><p> 'username' => Schema::TYPE_STRING.'NOT NULL',</p><p> 'auth_key' => Schema::TYPE_STRING,</p><p> 'password_hash' => Schema::TYPE_STRING.'NOT NULL',</p><p> 'password_reset_token' => Schema::TYPE_STRING,</p><p> 'email' => Schema::TYPE_STRING.'NOT NULL',</p><p> 'role' => Schema::TYPE_SMALLINT,</p><p> 'status' => Schema::TYPE_SMALLINT,</p><p> 'created_at' => Schema::TYPE_TIMESTAMP,</p><p> 'updated_at' => Schema::TYPE_TIMESTAMP,</p><p> ]);</p><p> $this->createIndex('username', 'user', 'username', true);</p><p> $this->createIndex('email', 'user', 'email', true);</p><p> $this->createTable('profile', [</p><p> 'id' => Schema::TYPE_PK,</p><p> 'user_id' => Schema::TYPE_INTEGER.'NOT NUL',</p><p> 'fullname' => Schema::TYPE_STRING.'NOT NULL',</p><p> 'created_at' => Schema::TYPE_TIMESTAMP, </p><p> ]);</p><p> $security = yii::$app->security;</p><p> $this->batchInsert('user', ['username', 'auth_key', 'password_hash','email','role','status','created_at'],[</p><p> ['admin',$security->generateRandomString(),$security->generatePasswordHash('admin'),'admin@admin.com',10,1,date("Y-m-d H:i:s")],</p><p> ['demo',$security->generateRandomString(),$security->generatePasswordHash('demo'),'demo@demo.com',1,1,date("Y-m-d H:i:s")],</p><p> ]);</p><p> $this->batchInsert('profile', ['user_id','fullname','created_at'], [</p><p> [1,'Administrator',date("Y-m-d H:i:s")],</p><p> [2,'Demostration',date("Y-m-d H:i:s")],</p><p> ]);</p><p> }</p><p> public function down() {</p><p> $this->dropTable('user');</p><p> $this->dropTable('profile');</p><p> }</p><p> /*</p><p> // Use safeUp/safeDown to run migration code within a transaction</p><p> public function safeUp()</p><p> {</p><p> }</p><p> public function safeDown()</p><p> {</p><p> }</p><p> */</p><p>}</p>
>>>รบกวนอาจารย์ช่วยดูโค้ดให้หน่อยครับว่าผิดตรงไหนบ้างครับ.....ไม่ create table เลยครับ ทำตามอาจารย์ทุกอย่างแล้วแต่ในฐานข้อมูลไม่มีการ Create Table เลย....มือใหม่หัดเล่นครับ<<<
<?php
use yii\db\Schema;
use yii\db\Migration;
class m150724_021725_create_user_profile_table extends Migration
{
public function up() {
$this->createTable('user', [
'id' => Schema::TYPE_PK,
'username' => Schema::TYPE_STRING.'NOT NULL',
'auth_key' => Schema::TYPE_STRING,
'password_hash' => Schema::TYPE_STRING.'NOT NULL',
'password_reset_token' => Schema::TYPE_STRING,
'email' => Schema::TYPE_STRING.'NOT NULL',
'role' => Schema::TYPE_SMALLINT,
'status' => Schema::TYPE_SMALLINT,
'created_at' => Schema::TYPE_TIMESTAMP,
'updated_at' => Schema::TYPE_TIMESTAMP,
]);
$this->createIndex('username', 'user', 'username', true);
$this->createIndex('email', 'user', 'email', true);
$this->createTable('profile', [
'id' => Schema::TYPE_PK,
'user_id' => Schema::TYPE_INTEGER.'NOT NUL',
'fullname' => Schema::TYPE_STRING.'NOT NULL',
'created_at' => Schema::TYPE_TIMESTAMP,
]);
$security = yii::$app->security;
$this->batchInsert('user', ['username', 'auth_key', 'password_hash','email','role','status','created_at'],[
['admin',$security->generateRandomString(),$security->generatePasswordHash('admin'),'admin@admin.com',10,1,date("Y-m-d H:i:s")],
['demo',$security->generateRandomString(),$security->generatePasswordHash('demo'),'demo@demo.com',1,1,date("Y-m-d H:i:s")],
]);
$this->batchInsert('profile', ['user_id','fullname','created_at'], [
[1,'Administrator',date("Y-m-d H:i:s")],
[2,'Demostration',date("Y-m-d H:i:s")],
]);
}
public function down() {
$this->dropTable('user');
$this->dropTable('profile');
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}
ตอบ/อธิบาย