2017-07-27 100 views
1

我有下面的類/遷移命名空間中缺少文件夾前端

use yii\db\Schema; 

class m170727_180101_Bewerbungen extends \yii\db\Migration 
{ 
    public function safeUp() 
    { 
     $tableOptions = null; 
     if ($this->db->driverName === 'mysql') { 
      $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; 
     } 

     $this->createTable('bewerbungen', [ 
      'bew_id' => $this->primaryKey(), 
      'datum' => $this->date()->notNull(), 
      'firma' => $this->string(100)->notNull(), 
      'rechtsart' => $this->integer(11), 
      'stadt' => $this->string(100)->notNull(), 
      'plz' => $this->integer(11)->notNull(), 
      'strasse_nr' => $this->string(100), 
      'ansprech_person' => $this->string(100), 
      'email' => $this->string(50)->notNull(), 
      'feedback' => $this->integer(11), 
      'bemerkungen' => $this->string(150), 
      'FOREIGN KEY ([[feedback]]) REFERENCES nachricht ([[id_message]]) ON DELETE CASCADE ON UPDATE CASCADE', 
      'FOREIGN KEY ([[rechtsart]]) REFERENCES rechtsform ([[id_recht]]) ON DELETE CASCADE ON UPDATE CASCADE', 
      ], $tableOptions); 

    } 

    public function safeDown() 
    { 
     $this->dropTable('bewerbungen'); 
    } 
} 

每個試圖讀出方法safeUp()拋出錯誤:

Unable to find 'frontend\migrations\m170727_180101_Bewerbungen' in file: E:\xampp\htdocs\Yii2_Mail/frontend/migrations/m170727_180101_Bewerbungen.php. Namespace missing?**

這裏是我的腳本:

namespace frontend\migrations; ... 

$connect=new m170727_180101_Bewerbungen(); 
$connect->safeUp(); ... 

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

這到底是什麼? 使用這樣的同樣的錯誤:

$connect=new \frontend\migrations\m170727_180101_Bewerbungen(); 

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

回答

1

嘗試,因爲在你的文件中沒有命名空間,以便自動加載機無法找到使用完整路徑

$connect=new \frontend\migration\m170727_180101_Bewerbungen(); 
0

你得到這個錯誤它。

但這不是真正的問題 - 你沒有正確使用Yii 2遷移。按照Yii2 Migration Guide

此外,由於你放在frontend這種遷移你可能想看看Namespaced Migrations實際添加的命名空間,並有正常運行。

相關問題