Yii Migration Issues

Hi Guys,

I have Just migrated from Yii 1.1.5 to Yii 1.1.6 and hit a snag while testing it. Where do I need to run the command from ? This has not been explained in the documentation. My guess was to run it in the application folder but running


yiic migrate create create_test_table

gave me the following error


Error: The migration directory does not exist: application.migrationskevin@kruschev:/development/projects/authentication$ 

I have tried to create the protected/migrations directory manually but the same error still persists.

I’m very new to Yii and was working this problem last night. I love migrations in Rails and they’ll be great for Yii.

In MigrateCommand.php, Yii passes $migrationPath which equals ‘application.migrations’ to Yii::getPathOfAlias and it returns “path to YiiRoot\framework\cli\migrations”. When you create a migrations directory in the Cli folder migrations do work.

I don’t know how to get them to be created in your project’s protected folder, but that would be preferable.

Just use yiic from your application directory, not from framework directory. Framework one should be used only to generate application and some other utility tasks.

I am running yiic from my application directory, not from the framework directory. Yii wants to create the migrations in framework/cli rather than application/protected

You need to configure the ‘basePath’ property in your console application’s config file to point to your protected directory.

qiang

It should be generated by yiic app, right?

It works fine with new projects created with yii 1.1.6, but not projects that I upgraded from 1.1.5 and converted to 1.1.6. I’ll have to figure out where I messed the upgrade.

Any idea on the procedures required to make it work with the previous yii versions ?

If you upgrade you’ll have to create protected/migrations as this is the folder where migrations are stored. Yii will not create this automatically (only if you create a new 1.1.6 app).

Please check what is returned Yii::getPathOfAlias(‘application’) in your console application. If it is different from something like ‘protected’, you need to check if you set ‘basePath’ configuration in your console app’s config (it should be there if you create your yii app using yiic webapp command).

When I run Yiic from the framework folder, Yii::getPathofAlias(‘application’) returns “path to framework”/cli/migrations

When I run it from the protected folder it returns "protected/migrations".

When I installed Yii 1.1.5, I added the framework folder to my path so I didn’t have to type the location of yiic all the time. This seemed to work with 1.1.5. When you run migrations from 1.1.6, you must run the yiic from the protected directory in your application tree for migrations to work. The one in the framework folder writes the migrations in cli/migrations.

the protected/config/console.php has set to ‘basePath’=>dirname(FILE).DIRECTORY_SEPARATOR.’…’,

I just started to teach myself Yii Saturday evening so I’m a huge noob. Coming from Rails I was very happy to see 1.1.6 with migration support released on Sunday. I’m hardly an expert on this.

Thank you, I figured that out. I don’t think 1.1.6 is created the protected/migrations folder. I had to create it manually with new projects started with 1.1.6

Strange enough I’m still getting the same error even after creating a new yii app using 1.1.6

Can you post step-by-step instruction of what you are doing so we’ll try to reproduce it and fix or document it?

[list=1]

[*]I first create the app by issuing the command


yiic webapp /path/to/my/dir

[*]After that I then go to my application folder and issue the command


yiic migrate create sample_migration_script

and I still get the same error.

[*]I have tried the same command in the protected folder but still nothing positive would come out of it.

[/list]

Thanks guys for your support. I have seen where I had it wrong. I had added the


/yii-1.1.6/framework

directory to PATH environment variable so as to use the yiic command line tool globally.

I did a probe and noticed that there exists another yiic executable in


application/protected

directory. What was happening before was that every time I called the command then the one in /yii-1.1.6/framework/ was called hence the path related issues. I guess it would be handy if the tutorial could be updated to explicitly explain where to run the command from for the the sake of future readers.

This is exactly what I did too. All other yiic commands seem to work from the framework and can be run from the application root, but migrations require you to run them from the protected folder below the application root.

Should the yiic migrate command create the migrations folder if it’s does not exist?

Also, anybody else notice that the migration template is missing the php close tag at the end of the file?

I’d also recommend that the comment lines around the down function be removed. For proper migrations, the down function is equally as important as the up function. Commenting out the down function in the template implies that it is not important.

I’ve attached a diff with those changes.

Cheers,

Keith

Maybe. I don’t remember if it’s created via yiic webapp. If it is then it should not create folder every time it runs.

That’s intentional. There are no close tags in all framework files.

Comments are showing that it’s optional. And it is. There are situations when you can’t implement down.

This is what did the trick for me




$> cd ....../protected

$> mkdir migrations

$> ./yiic migrate create foobar



NOTE the ./ before the yiic command

cheers

ps If this answer was already given somewhere in this post, please ignore my post!