CakePHP 2 Bake unable to create a Model - cakephp

I am trying to create a model through Cake Bake command.
I am using windows and II7. I have set up the global variables on the system path so i can do "cake bake" on my Command Prompt.
I have my database config defined in App/config/database.php
Once i do it, i press M for Model, then i select the default database and the console shows this message:
Your database does not have any tables.
And i am not able to create any model for my project.
If i manually create a table on my DB, the error changes and it shows this: http://www.subirimagenes.com/imagen-picture-8000920.html
What's the problem with it? Of course i have no tables if i have just installed Cake!!

First, create your tables with, let's say, phpMyAdmin (localhost/phpmyadmin).
Then, if you have properly configured your database configuration in app/config/database.php you will see Models in your Bake script you can create.

refer below links to get step by step methodology in cake bake
http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html
http://www.jamesfairhurst.co.uk/posts/view/baking_with_cakephp
you can also check environment variable settings for this error

Related

How to create database using Database Project in Visual Studio if doesn't exists?

I have a Database project for my personal project and I am trying to deploy my code to my DEV server. I frequently delete and re-create my DEV Server. Right now, DEV Server is newly created with SQL Server. Every time I want to deploy my code I have to manually create Database Project and then publish database project. I want to automate creation of Database with database project deployment.
Right now, I have a script that creates database, but I have to execute it manually. And this is working perfectly but I want to automate this step as well.
Is this even possible? If yes, then how? Please explain step by step. Also what will we mention for Initial Catalog in connection string?
Edit:
I tried to create Database by using
CREATE DATABASE LocalDbTest
in Pre-Deployment Script. But it didn't work. It is creating Database, but then tables are not getting created tables under it. Since I used master database as default database, it is creating table under master. It is not letting me select LocalDbTest database as default because it is not yet created, so I have to select Master as my default database. I tried to Change Database by:
USE LocalDbTest
GO
I used it just after creating Database but this didn't work because when generating script it is changing back to default database. This part is coming automatically when generating script.
USE [$(DatabaseName)];
GO
Also Visual Studio is not letting me add database name in front of table name like:
CREATE TABLE [LocalDbTest].[dbo].[TestTable]
I am getting error:
When you create an object of this type in a database project, the object's name must contain no more than two parts.
If you have a script ready for database creation, you can use the Pre-build event to call SQLCMD and run your script.
Edit:
If you have trouble pointing to a database that does not exist, you may have to manually edit the publish profile (ex. dev.publish.xml) and set the TargetDatabaseName element explicitly. You can also set CreateNewDatabase element to True if you want to be recreated every time it gets published.
Answer:
You can use a publish profile and hardcode the target database in it.

CakePHP/CakePHP 2.4 app

I am currently developing a CakePHP 2.4 app and trying to manage changes to my database table schemas with the schema manager. I figured out how to generate the schema and restore it, but is there a way to backup the entire database's schema with it? Seems like should be a method to solve this... Any thoughts?
Of course, use the schema dump command from the Cake Console.
It will write the entire schema to a .sql file and store it in App/Config/Schema.
Example of usage:
Console/cake schema dump --write filename.sql
(change 'filename.sql' to whatever the dump file should be called.)
This can also be find in the cake docs:
http://book.cakephp.org/2.0/en/console-and-shells/schema-management-and-migrations.html
There is actually a better way to handle this using the CakeDC Migrations Plugin, this gives you Rails type "migrations" that will help you snapshot your schema, it is an improvement to the cake schema dump method specified above and is actually developed by the CakePHP core team.
CakeDC Migrations
You can dump your schema using cake schema command
First of all you have to set the cake command path
In the windows system you have to set the path of the console/cake
Go to the cmd
Write the command "Console/cake schema generate" from this you can generate schema
After that if you want to dump in to the sql file So, You have to use following command "Console/cake schema dump --write filename.sql"
For more information click on below link
http://book.cakephp.org/2.0/en/console-and-shells/schema-management-and-migrations.html

Scripting FileTables

Scenario:
I have 3 environments that I am using, Dev, UAT and Live. Each of which having it's own database, MyDb_Dev, MyDb_UAT, MyDb_Live.
Then I have a VS2012 Database project in my solution that contains all my scripts. This works nicely when I make changes to my model database (MyDb_Model) that is located locally.
What I want to do:
I want to use the FileTables in SQL 2012 (which I understand how to set up), however I don't know how to script them to be able to configure the options to handle my environments. When I generate the scripts, it will hard code the name to be MyDb_Model as the FileGroup. Also, that said, when I do try and publish to my Dev database, it's complaining about the database options not being able to take the new scripts. When I script include the options of the Model database, it'll complain when I try to publish to my Dev database because of duplicating names.
Question:
Can you script FileTables (with the database options) using the database project in V2012 to be configurable or do I need to manually make my own scripts?
Prefered:
Compare MyDb_Model to Database project.
Publish to MyDb_Dev as a newly created database.
Sounds like you'll want project variables to handle this where the variable contains the environment-specific text for each. You'd then use that variable in your objects instead of the hard-coded paths. The following would create a FileTable called "DocumentStore" and use the value for a variable called "FileTableDirectoryVariable" that you set up in your Project Properties - SQLCMD Variables. Set each of those in your Publish Profiles to use the correct directory, and you should be good. If you're using different filegroups for these tables, you should be able to tweak the FileGroup setting in a similar manner using a SQLCMD Variable.
CREATE TABLE DocumentStore AS FileTable
WITH (
FileTable_Directory = '$(FileTableDirectoryVariable)',
FileTable_Collate_Filename = database_default
);
GO

executing EntityFramework4Domain.edmx.sql

I'm creating an application that uses Entity Framework 4 as the ORM. I'm using the designer and have generated the Domain.emdx.sql file to create the database.
So far, I've just run that edmx in sqlserver manually to create the db, but I'm now working on a lightweight installer and I'd like to connect to the db if it exists and run the sql script to create the database, after which I'll use my repositories to insert all of the default values that the db should be populated with.
I would like to be able to load the edmx.sql file so that it will always take the most current changes without having to copy the contents of that file into some resource manually, but I can't seem to find out how to get at its contents in code. It's not in the build folder and it doesn't appear to be directly accessible in code.
How might I do that?
You can try using the CreateDatabaseScript method. It will provide you with the script.
However, looks like you need the CreateDatabase method of the ObjectContext class, this method will simply create a database.

Why am I getting errors after renaming my database in CakePHP?

After I uploaded my application created using cakephp, I found out that I had to rename the database. I renamed my database accordingly and changed the settings in the database.php file in the "config" folder. But my application is still not running.
I am being shown this error message
"Missing Database table"
"Error: Database table tbl_topics for model Topic was not found."
I have double checked the existence of tbl_topics in the database (it is there in the database) but the application says "table not found"
what might be the problem, please help me out...
Make sure the host/user/pass that you've set-up in the config.php file have access to that database and table
You could also try running cake schema generate --dry which will spit back any problems with the connection that you might be having
Also have a look in your app/tmp/logs for some extra information on the problems you are experiencing
Take the username and password you are using for cakephp and it's db connection and connect to the database from the command line. I'm presuming you are using a unix-type system and mysql?
mysql --user=user_name --password=your_password db_name
...and then try to run a simple select:
SELECT * FROM tbl_topics
If you get an error there, it will at least identify that it is a low level db problem and the likely solution is that you need to grant permissions to that username to select from that database. Your current access levels for that user is probably granting access to the db under the old name.
You have probably uploaded your cache files as well. Make sure you delete all the files in /app/tmp/cache/*
Warning: Don't delete the folders, files only!
Also, make sure your tmp folder and all the subfolders are world-writable.
One last thought would be to check your model cache. I don't know why that would impact you with respect to connecting, but it's worth taking a look in app/tmp/cache.
:-)
finally got it.... :-D
I forgot to assign the user access to my application's database on main server. After assigning the permissions all went fine.
Anyways thank you all for your valuable answers... It helped me gain some additional knowledge about cakephp.

Resources