Modify existing schema for SonataPageBundle: page__site doesn't exist - php

After finally(!) adding SonataPageBundle to an existing app I get when going to the dev environment
SQLSTATE[42S02]: Base table or view not found: 1146 Table
'volunteer.page__site' doesn't exist
on running php app/console sonata:page:create-site. Nowhere in the documentation for the PageBundle is there any mention of how to create the schema.
If I do doctrine:schema:create --dump-sql to see what's what I get
[Doctrine\DBAL\DBALException]
Unknown column type "json" requested...

A search in the installed PageBundle directory (i.e., not at the Sonata-Project website) revealed the instruction to modify app/config/config.yml with
doctrine:
dbal:
...
types:
json: Sonata\Doctrine\Types\JsonType
With this addition the schema could then be updated and a site created.
If my sanity holds I'll fork the documentation to have it match a known good procedure.

Related

Laravel Error - Base table or view not found

I am trying to run this code I cloned, but I keep getting this error..
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'roocket.permissions' doesn't exist (SQL: select * from `permissions`)
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'roocket.permissions' doesn't exist-Vue-Dashboard/blob/master/src/pages/Pages/RTLPage.vue
I have run composer install and npm install , and I am new to the laravel world.
I have uploaded the repo to my github https://github.com/arya107/laravelbackend.
I have connected the DB via XAMPP and I don't know what the problem is.
Basically, the fix for me was that I needed to comment out
{
Gate::define($permission->name , function ($user) use($permission){
return $user->hasRole($permission->roles);
});
}
Then, I was enabled to install it, and then I re-enabled the code :)
php artisan migrate
You are missing the DB table. Run the migrations included in the project to create the tables in your DB.
The migration is creating the field and relationship at same time. I would try to use separated migrations, as this answer explains:
But I always create a foreign key in a separate Schema::table() command, because some databases need you to have the column before attaching the constraint to it
I think (haven't tried it) that your database engine does not accept the creation of the foreign key relation because the FK field was not created yet.
You can also try to do a full migrate using:
php artisan migrate:fresh
That command will drop all your database tables, so be careful!

Can we Alter a table (entity) in Symfony 2.7.3 ? using CMD or manually?

Can we Alter a table Using Command Prompt in Symfony 2.7.3 ?
I have 3 Fields in an entity i.e. Product.
Now i want to add new field in existing Entity, also i want to modify field type of declared field.
I have used
php app/console schema:update --force
I have tried manual changing in Entity product.php, after manually changing entity file still not working. Kindly guide me accordingly. Thanks
While you are generating entity, symfony ask you to choose
configuration format for mapping information:
here you should choose annotation format type,
i was choosing yml format and after generating entities i could not update my schema with:
doctrine:schema:update --force
it was always showing me nothing to update your database is already sync with current entity metadata
then i generated a new entity and set configuration format type = annotation and after that now i can modify my entity with php (Product.php) and with doctrine:schema:update --force its working fine and my DB Table is ALTERING perfect.
Altering the entity via the command line is not possible but creating a new one is with php app/console doctrine:generate:entity - but that doesn't help you. You may only alter the entity manually (that is, by editing the entity.php file).
After changing the file you must run php app/console doctrine:schema:update --force for the change to affect your database. Notice that this command is slightly different than the command you tried to run. Be aware, using this command should not be used on your production server.

Symfony 2 Doctrine MS SQL Error

I have started working on a Symfony 2.3 project where I need to convert a financial website written in classic Asp to Php.
The client has Ms-Sql database which is to be used with Symfony 2.3 and doctrine, I have made the database and loaded the empty tables from the schema files.
Now whenever i try to generate entities from the database(Ms-Sql) I get the following error:
Doctrine\DBAL\DBALException
Unknown database type timestamp requested, Doctrine\DBAL\Platforms\SQLServer2008Platform may not support it
Does anyone know how to solve the problem or what should I do to avoid such a situation?
Kindly help me as I am new to Symfony 2.3, Thank you
You can add your own types following doctrine doc about the subject :
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/mysql-enums.html
this is concerning enum type but you can use it with any type like timestamp and link it to string type or whatever other supported type by your database which fit you best.
src/My/Project/MyProjectBundle.php
public function boot()
{
$em = $this->container->get('doctrine.orm.entity_manager');
$em->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('timestamp','string');
}
and normally all your timestamp types should be translated as string.
The configuration below works on Synfony 3.2
1) in config.yml add the new type under types and map it under mssql connection
# Doctrine Configuration
doctrine:
dbal:
types:
timestamp: AppBundle\Type\Timestamp
..
..
connections:
mssql:
driver: sqlsrv
host: "%mssql_host%"
port: "%mssql_port%"
dbname: "%mssql_db_name%"
user: "%mssql_user%"
password: "%mssql_password%"
mapping_types:
timestamp: timestamp
2) Create the class AppBundle\Type\Timestamp as for the following url:
https://github.com/mmerian/doctrine-timestamp/blob/master/lib/DoctrineTimestamp/DBAL/Types/Timestamp.php
3) generate entities from the database with the following command:
php bin/console doctrine:mapping:import --force AppBundle xml --em=mssql

Cannot create postgres database with Doctrine

I have project in Symfony2 with doctrine. In one moment i loose ability to create/drop databases via console commands like
app/console doctrine:database:drop --force
app/console doctrine:database:create
app/console doctrine:schema:update --force
If i attemp to create database, doctrine give me next error:
[Doctrine\DBAL\Exception\ConnectionException]
An exception occured in driver: SQLSTATE[08006] [7] FATAL: database "motherhood" does not exist
So, i can create database in psql with user, written in symfony config. If i try to drop existing database via Doctrine, it gives me this:
SQLSTATE[55006]: Object in use: 7 ERROR: database "motherhood" is being accessed by other users
DETAIL: There are 1 other session using the database.
But there is no connection to this database
The quick fix for the problem is to create a database with the same name as user executing the command, because PostgreSQL must connect to a database, even when creating a new one.
The failure when dropping the database should be fixed in DoctrineBundle 1.4.
The failure to create the database will be fixed in doctrine/dbal in the very next release (2.5.2) as mentioned here: https://github.com/doctrine/DoctrineBundle/issues/402 . The problem will be fixed by always connection to the template database, which cannot be dropped.

zf2 generating entity with doctrine ORM

I have Entity classes generated with Doctrine ORM, and ZF2.
I changed a table structure and I want to update an entity class, so I am trying to regenerate the entity class but it's not working.
I used the following code:
vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Album\Entity\" --force --from-database annotation ./module/Album/src/clear
I got the error:
[Doctrine\ORM\Mapping\MappingException]
Property "status" in "Album\Entity\TestRun" was already declared, but it must be declared only once
orm:convert-mapping [--filter="..."] [--force] [--from-database] [--extend[="..."]] [--num-spaces[="..."]] [--namespace[="..."]] to-type dest-path
I want to re-generate the entity class for a particular table
If you change the structure of your Entity file a simple
\vendor\bin\doctrine-module orm:schema-tool:update --force will alter the table according to your Entity definition.
If you still want to recreate the table simple drop the table from your mysql and run the update command. You may have some cache files left so clearing those might be a good Idea, too.
You can clear the complete cache like so:
\vendor\bin\doctrine-module orm:clear-cache:query
\vendor\bin\doctrine-module orm:clear-cache:result
\vendor\bin\doctrine-module orm:clear-cache:metadata
As mentioned above it might be a bad practice, but nevertheless I use the following commands to achieve the result you are asking about:
vendor\bin\doctrine-module orm:convert-mapping --filter='Evaluation' --namespace='MyModule\Entity\\' --force --from-database annotation ./module/MyModule/src/
and another command to generate getters and setters:
vendor\bin\doctrine-module orm:generate-entities --filter='Evaluation' ./module/MyModule/src/ --generate-annotations=true

Categories