代码之家  ›  专栏  ›  技术社区  ›  tklustig

命名空间缺失

  •  1
  • tklustig  · 技术社区  · 7 年前

    我在文件夹前端/迁移中有以下课程

    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()都会抛出错误:

    在以下文件中找不到“frontend\migrations\m170727\u 180101\u Bewerbungen”:E:\xampp\htdocs\Yii2\u Mail/frontend/migrations/m170727\u 180101\u Bewerbungen.php。命名空间缺失**

    namespace frontend\migrations; ...
    
    $connect=new m170727_180101_Bewerbungen();
    $connect->safeUp(); ...
    

    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    这到底是什么? 同样的错误如下:

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

    2 回复  |  直到 7 年前
        1
  •  1
  •   ScaisEdge    7 年前

    尝试使用完整路径

     $connect=new \frontend\migration\m170727_180101_Bewerbungen();
    
        2
  •  0
  •   Bizley    7 年前

    但这不是真正的问题-您没有正确使用Yii 2迁移。遵循 Yii2 Migration Guide .

    frontend 你可能想看看 Namespaced Migrations 在那里实际添加命名空间并正确运行。