Yii Migrations

Hey everyone,

I was able to get database migrations working a few weeks ago and I can’t seem to replicate what I did for the life of me. I am running windows and I am following a tutorial to create a trackstar app as I am new. I have the projected inside of “C:\xampp\htdocs\yii\trackstar” I need to setup a database migration script but I get the error: the migration directory does not exist when I run “yiic migration create create_table_tbl_user” and I have tried all sorts to point it to the migrations directory inside the project folder. Please can some one help me? This is driving me mad

Post your config and directory tree right inside the protected dir.

How do you mean?

Post the contents of the protected/config/main.php and protected/config/console.php files and the contents of your ‘protected’ directory so we can make sure your migrations directory is there.

Main:




<?php


// uncomment the following to define a path alias

// Yii::setPathOfAlias('local','path/to/local-folder');


// This is the main Web application configuration. Any writable

// CWebApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'Trackstar',


	// preloading 'log' component

	'preload'=>array('log'),


	// autoloading model and component classes

	'import'=>array(

		'application.models.*',

		'application.components.*',

	),


	'modules'=>array(

		// uncomment the following to enable the Gii tool


		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'abcd1234',

			// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

		),


	),


	// application components

	'components'=>array(

		'user'=>array(

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

		),

		// uncomment the following to enable URLs in path-format


		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),


		'db'=>array(

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		),

		// uncomment the following to use a MySQL database


		'db'=>array(

			'connectionString' => 'mysql:host=localhost;dbname=trackstar',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

		),


		'errorHandler'=>array(

			// use 'site/error' action to display errors

			'errorAction'=>'site/error',

		),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=>'web@web.com',

	),

);



console:


<?php


// This is the configuration for yiic console application.

// Any writable CConsoleApplication properties can be configured here.

return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'My Console Application',


	// preloading 'log' component

	'preload'=>array('log'),


	// application components

	'components'=>array(

		'db'=>array(

			'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',

		),

		// uncomment the following to use a MySQL database

		/*

		'db'=>array(

			'connectionString' => 'mysql:host=localhost;dbname=testdrive',

			'emulatePrepare' => true,

			'username' => 'root',

			'password' => '',

			'charset' => 'utf8',

		),

		*/

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

			),

		),

	),

);

and my protected folder is as follows:

commands

components

config

controllers

data

extensions

messages

migrations

models

runtime

tests

views

/* Moved to General Discussion */

(not a tip, snippet or tutorial)

I think you switched to MySQL in your web app but forgot to adjust the console config, so migrations try to apply to your old SQLite database, which probably is invalid.