Namespace missing

I have following class in folder frontend/migrations




<?php


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');

    }

}

?>



Each try to read out method safeUp() throws out error:

[b]

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

[/b]

Here is my script:




namespace frontend\migrations; 

.

.

.


$connect=new m170727_180101_Bewerbungen();

$connect->safeUp();

.

.

. 



What the hell is that? I’ll get exactly same error, using like this:




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



migrations are usually not namespaced in yii, you could try changing it to




// in migration file put this after the <?php tag

namespace frontend\migrations;


// try this in your script

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

$connect->safeUp();

Thx a lot. This solved problem. No error any more!

Can i use migration without writing code, just in console(cmd)?

yii migrate/new has no effect?!

create not new


yii migrate/create yourNameHere

Thx for your help.

Now, I can go marching on…

B)