CakePHP: Error trying to generate a schema - php

I'm trying to start using CakePHP schema: app/Console/cake schema generate
I get the following error:
Welcome to CakePHP v2.3.0 Console
---------------------------------------------------------------
App : app
Path: /Applications/MAMP/htdocs/mysite/app/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Error: Database connection "Mysql" is missing, or could not be created.
This is confusing because the site is running fine, so the DB credentials in Config/database.php are correct.
Update:
Because I'm using MAMP, I added the following to my Config/database.php in the $defualt array:
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
Now I don't get the original error, but rather some new ones:
Welcome to CakePHP v2.3.0 Console
---------------------------------------------------------------
App : app
Path: /Applications/MAMP/htdocs/mysite/app/
---------------------------------------------------------------
Cake Schema Shell
---------------------------------------------------------------
Generating Schema...
Notice Error: Schema generation error: invalid column type enum('normal','unlimited_time','admin','extra_time') for Attempt.type does not exist in DBO in [/Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php, line 616]
Notice Error: Schema generation error: invalid column type enum('in_progress','complete','canceled') for Attempt.status does not exist in DBO in [/Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php, line 616]
Notice Error: Schema generation error: invalid column type enum('MC','FI','CS','CQ','TF') for AttemptedQuestion.type does not exist in DBO in [/Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php, line 616]
Notice Error: Schema generation error: invalid column type enum('1','2','3') for Category.category_order does not exist in DBO in [/Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php, line 616]
Error: Table choices for model Choice was not found in datasource default.
#0 /Applications/MAMP/htdocs/mysite/lib/Cake/Model/Model.php(3217): Model->setSource('choices')
#1 /Applications/MAMP/htdocs/mysite/lib/Cake/Model/CakeSchema.php(260): Model->getDataSource()
#2 /Applications/MAMP/htdocs/mysite/lib/Cake/Console/Command/SchemaShell.php(149): CakeSchema->read(Array)
#3 /Applications/MAMP/htdocs/mysite/lib/Cake/Console/Shell.php(388): SchemaShell->generate()
#4 /Applications/MAMP/htdocs/mysite/lib/Cake/Console/ShellDispatcher.php(199): Shell->runCommand('generate', Array)
#5 /Applications/MAMP/htdocs/mysite/lib/Cake/Console/ShellDispatcher.php(67): ShellDispatcher->dispatch()
#6 /Applications/MAMP/htdocs/mysite/app/Console/cake.php(33): ShellDispatcher::run(Array)
#7 {main}
Looks like CakePHP is freaking out about the ENUM fields.

As described pretty definitively here...
Cakephp + enum support : unable to save or select enum 0 and 1
...CakePHP does not like ENUM fields. It looks like the Console tools related to the schema are going to work with them there.

Old question, I know. But I just fixed this issue yesterday while working in a really old project of mine.
If you still need this kind of solution, I posted on this git public repository.
https://github.com/matheuscmpm/cakephp-schema-enum
You basicly need to alter the Datasource/Database/Mysql.php file to insert the ENUM as an accepted type and them alter the Model/CakeSchema.php to handle them.
If you don't want to alter your cakephp 2.x files, you can copy them to your project app folder, just like I did. In this README.md file, you can see what exactly I changed in this both files, you can replicate the same solution to handle SET type fields as well.
I just did that to work with MySQL, so with you need to another database, you will also need to change a couple things in others datasource/database files.
Cheers.

Related

Laravel FatalErrorException in Handler.php line 25

I'm getting the following error on random occasions, working on a Laravel 5.1 project on the latest homestead with PHP7
FatalErrorException in Handler.php line 25:
Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of TypeError given, called in /home/vagrant/Code/henau/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 73 and defined in /home/vagrant/Code/henau/app/Exceptions/Handler.php:25
Stack trace:
#0 /home/vagrant/Code/henau/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(73): App\Exceptions\Handler->report(Object(TypeError))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(TypeError))
#2 {main}
thrown
Even when I undo work that has been causing it, It stays. It's being caused by this block of code in this instance
\Mail::send('emails.registered', $user, function ($m) {
$m->to('miguel#dummyaddress.com')->subject('New Order');
});
It seems to me the error is not directly code-related. I've seen other people encounter it in complete different situations. And i've seen it popup in older threads regarding Homestead and PHP7. There was an askubuntu thread but it's offline, So I hope we can reopen the discussion here.
Solution
This is actually an error that an exception can't be shown. This is caused by using PHP7.x on an older Laravel project that requires PHP5.6.x
My solution was to create a new Homestead specific for this project and install php5.6 on that homestead using an older version of laravel/homestead
I had the same problem when running seeders Notflip . I'm usign Laravel framework 5.0.34. I had this structure:
App/Models/Users/ (My users's Models here)
After moving my users's models to the App directory, my seeder problem was solved.
Check your namespaces and put under consideration your Laravel Framework version before make changes in the framework.
Hope it helps!
This situation occur when laravel project version not compatible or not configured with your local installed version So the laravel not tracking the exact error and instead of showing exact error on line shows that type of errors
i had same problem in laravel 5.1. After reading this issue, i found out i was using laravel v5.1.0 and that seemed wrong so changed 5.1.0 to 5.1.* and ran composer update. this solved the issue for me.

PHP project works locally perfect and on external host it doesn't

I'm new with PHP and created a demo rest API so I can test my "in development" Android app to work with API's and Json
Te demo API works fine on my desktop with XAMPP but when I upload the project to my external hosting provider i constantly get errors. Some of them I fixed by myself but now I have error I can't get fixed.
Project information:
- Use MySQL Database
-- Tables are exported from desktop to external host
-- Database connection is updated with the external information
- Use doctrine as ORM
-- Works without any problem on my local setup
The error(s)
[18-Feb-2016 09:36:32 Europe/Amsterdam] PHP Fatal error: Uncaught Doctrine\ORM\Mapping\MappingException: The target-entity DemoApi\src\child cannot be found in 'DemoApi\src\Alert#Child'. in /home/aaapi/public_html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php:740
Stack trace:
#0 /home/aaapi/public_html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php(953): Doctrine\ORM\Mapping\MappingException::invalidTargetEntityClass('DemoApi\\src\\chi...', 'DemoApi\\src\\Ale...', 'Child')
#1 /home/aaapi/public_html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(198): Doctrine\ORM\Mapping\ClassMetadataInfo->validateAssociations()
#2 /home/aaapi/public_html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(177): Doctrine\ORM\Mapping\ClassMetadataFactory->validateRuntimeMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL)
#3 /home/aaapi/public_html/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(332): Doctrine\ORM\Mapping\ClassMetadataFactory->doLoa in /home/aaapi/public_html/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php on line 740
I'm sure that the files entity classes exist and are correct else it wouldn't work in XAMPP or are i'am wrong about that?
------------- UPDATE -------------
File permissions are 755 for all folders and 644 for all php files

SQLite3 / PDO - No such table though it does exist

I have a problem with an SQLite3 database where I can access it either with the sqlite3 command or with the PHPStorm built-in database manager but the application I am working on doesn't find the tables in it. It correctly connects to the database it seems.
This line of PHP causes the PDOException:
$query = "SELECT * FROM users";
$results = self::$app->db->query($query);
And the exception is simply SQLSTATE[HY000]: General error: 1 no such table: users. I am using the Slim framework, by the way.
I don't really know what to do as I am new to Slim as well as SQLite.
Thank you for your help :-)
The database that you have opened does not contain this table.
SQLite will happily open any file name; if it does not exist, it will create a new, empty database.
Check your database file name.
Thanks to the accepted answer that pointed me in the right direction.
I am using Symfony 4.1 and realized that the base directory for Symfony is the public directory (should be app in 2.8) so to open my database I had to do :
# file: PROJECT_ROOT/.env
DATABASE_URL="sqlite:///../my_super.db"
But then, every call to doctrine in a command (like doctrine:schema:update) must be called in a direct subfolder of the project, like so:
PROJECT_ROOT/bin$ ./console doctrine:schema:update --dump-sql

Doctrine\ORM\ORMException: This behaviour is (currently) not supported by Doctrine 2

I'm running an application stack which uses codeigniter along with doctrine2. I was successfully running the command line tool to generate my models, proxies and db till few days back. Y'day i made some additions to my XML mapping and now if i run
php doctrine-cli.php orm:create
it gives me the following error and exits:
[Doctrine\ORM\ORMException] This behaviour is (currently) not supported by Doctrine 2
How ever, i did
php doctrine-cli.php orm:validate-schema --verbose
Which gave me following message:
[Mapping] OK - The mapping files are correct.
[Doctrine\ORM\ORMException]
This behaviour is (currently) not supported by Doctrine 2
Exception trace:
() at C:\wamp\www\frsale\application\libraries\Doctrine\ORM\ORMException.php:12
8
Doctrine\ORM\ORMException::notSupported() at C:\wamp\www\frsale\application\lib
raries\Doctrine\ORM\Tools\SchemaTool.php:439
Doctrine\ORM\Tools\SchemaTool->_gatherRelationsSql() at C:\wamp\www\frsale\appl
ication\libraries\Doctrine\ORM\Tools\SchemaTool.php:213
Doctrine\ORM\Tools\SchemaTool->getSchemaFromMetadata() at C:\wamp\www\frsale\ap
plication\libraries\Doctrine\ORM\Tools\SchemaTool.php:711
Doctrine\ORM\Tools\SchemaTool->getUpdateSchemaSql() at C:\wamp\www\frsale\appli
cation\libraries\Doctrine\ORM\Tools\SchemaValidator.php:287
Doctrine\ORM\Tools\SchemaValidator->schemaInSyncWithMetadata() at C:\wamp\www\f
rsale\application\libraries\Doctrine\ORM\Tools\Console\Command\ValidateSchemaCom
mand.php:77
Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand->execute() at C:\wamp\
www\frsale\application\libraries\Doctrine\Symfony\Component\Console\Command\Comm
and.php:239
Symfony\Component\Console\Command\Command->run() at C:\wamp\www\frsale\applicat
ion\libraries\Doctrine\Symfony\Component\Console\Application.php:193
Symfony\Component\Console\Application->doRun() at C:\wamp\www\frsale\applicatio
n\libraries\Doctrine\Symfony\Component\Console\Application.php:106
Symfony\Component\Console\Application->run() at C:\wamp\www\frsale\application\
doctrine-cli.php:42
orm:validate-schema
Can somebody point me what could be the problem here.
NOTE: my entities and proxies are generated without any problem
EDIT: Closing this as i found the issue and it was nothing but the relation defined in mapping which was creating a problem.
This error usually occurs when there is a problem in Entity mappings. For example:
/**
* #OneToMany(targetEntity="Task", mappedBy="")
*/
private $task
Here above mappedBy property is not specified, which results in this error.

Magento 1.7.0.2 Upgrade (From 1.6.2)

I have recently caught wind of the inherent Zend problem that Magento is built upon. I took that initiative to upgrade my sites from 1.6.2 to the newest 1.7.0.2 to resolve that problem. All my sites upgraded beautifully except 1. All the files are up to date on the server now, but when I try to access my site and it runs the upgrades, I get the below report saved in my reports folder without access to my site.
a:5:{i:0;s:216:"Error in file: "/home/xxxxx/public_html/app/code/core/Mage/Sales/data/sales_setup/data-upgrade-1.6.0.4-1.6.0.5.php" - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main.base_tax_refunded' in 'field list'";i:1;s:883:"#0 /home/xxxxx/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(645): Mage::exception('Mage_Core', 'Error in file: ...')
#1 /home/xxxxxx/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(407): Mage_Core_Model_Resource_Setup->_modifyResourceDb('data-upgrade', '1.6.0.4', '1.6.0.7')
#2 /home/xxxxxx/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(286): Mage_Core_Model_Resource_Setup->_upgradeData('1.6.0.4', '1.6.0.7')
#3 /home/xxxxxx/public_html/app/code/core/Mage/Core/Model/Resource/Setup.php(269): Mage_Core_Model_Resource_Setup->applyDataUpdates()
#4 /home/xxxxxx/public_html/app/code/core/Mage/Core/Model/App.php(351): Mage_Core_Model_Resource_Setup::applyAllDataUpdates()
#5 /home/xxxxxx/public_html/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#6 /home/xxxxxx/public_html/index.php(87): Mage::run('', 'store')
#7 {main}";s:3:"url";s:1:"/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:7:"default";}
Or if I try to upgraded via the downloader I get:
Exception during cache and session cleaning: Error in file: "/home/xxxxxx/public_html/app/code/core/Mage/Sales/data/sales_setup/data-upgrade-1.6.0.4-1.6.0.5.php" - SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main.base_tax_refunded' in 'field list'
This is a problem I have yet to run into with my many moons of administering magento. Lookin into the code for that php, everything seems standard, and matches the other sites i have installed the upgrade on.
Anyone run into such an issue?
Ben, I've upgraded four Magento stores now to 1.7.0.2 from 1.5.1.0 and 1.6.2.0. Not exactly the same problem, but two had some form of missing table (one was a captcha_log, the other was sales_order_tax_item. Once I created the 'missing' table each installation was fine. Not sure why they were or went missing. Might you just add the missing column or replace the table with a correct version? base_tax_refunded is in the sales_flat_order table.
My problem is solved.
Turns out my index.php file was set to 666. Ran a chmod to change it to 755 and all is well again!
I've had the same problem but the field was in my main orders table and changing permissions of files had no effect, so eventually after looking at the files that was given the errors more closely (i.e. data-upgrade-1.6.0.4-1.6.0.5.php) I added following columns to the following tables and at last I can get back into my admin panel.
Columns Added: base_tax_refunded,discount_refunded,base_discount_refunded
to Tables: sale_flat_creditmemo,sales_flat_creditmemo_item,sales_flat_order_item
Surely this kind of thing would be done automatically by the upgrade scripts? unless I missed some step...

Categories