I use Symfony 6.1 , Doctrine, Fixtures, phpunit and Zenstruck Foundry Bundle.
The session is kept in the database.
In a WebTestCase I want to reset the test database and use the ResetDatabase trait for this.
But that doesn't work because the session table isn't deleted with doctrine:schema:drop
As soon as doctrine:schema:create is executed, there is an exception because the session table already exists.
I found out that the session table is on the blacklist and must not be deleted. It also doesn't work with "--full-database".
How do I have to configure the Foundry Bundle or Doctrine to make it work?
Please excuse my bad English
I found this, but unfortunately it doesn't offer a solution.
https://github.com/doctrine/orm/issues/8976
I guess I found the mistake.
Someone created a session entity. :(
This seems to affect the behavior of doctrine:schema:create.
Related
I am running sonata admin and I have an existing working entity/admin. I've added another 2 columns to the doctrine orm, the entity, the admin and ran the app/console doctrine:schema:update commands to get the fields in to the database successfully.
On local dev environment, this works great.
On production, the new fields aren't saving.
When saving the entity within sonata admin if I manually call $this->isMyNewField() in preUpdate or postUpdate I get the correct result of true or false depending on whether i checked the box or not.
However doctrine doesn't seem to be correctly registering the field at all, i've logged the sql that it is running on update and persist and it literally doesn't even try and do anything with the field whatsoever on either.
If I change the AppKernel to run on 'dev' rather than 'prod' (on production environment) then all works as expected and doctrine picks it up without an issue.
Ive tried clearing doctrine metadata, clearing cache, restarting servers, changing field types, removing in doctrine and re-adding (via the entity orm xml file)
Still no luck. Any other ideas I can try?
Thanks
Kevin
Hi all turns out it was the command
app/console doctrine:cache:clear-metadata
That needed running, I had tried this without success so the big thing I missed off it was the env so the command was
app/console doctrine:cache:clear-metadata --env=prod
Was fine after this, very frustrating
I'm trying to run
dotnet ef database update
When I do so, I get an error about not being allowed to CREATE TABLE. Not entirely surprising as I don't want the user I have the website running under to be able to create tables. So, after a bit of searching I found a solution that basically created an inherited context, and with that context used a different set of credentials. So, I tried;
dotnet ef database update --context ScaffoldContext
And I got the same error. I checked my connection string, yes, it's a user I can use to create a table with. Confirmed through SQL CLI. So, I added CREATE TABLE privileges to my site user, and the error changed. Suggesting that the base connection string was the one that mattered and it's ignoring using my elevated user. I tried moving the configuration into the OnConfiguring override in my inherited scaffold context, instead of services.AddDbContext in my Startup.cs. However, looking this up it looks like the wrong way to go about that. When I added CREATE TABLE privilege to my site user, I got a different exception about not being allowed to touch dbo.
This is driving me nuts, I don't want to use my site user as my migration user and it seems every example I find is from older versions of EF or dotnet core. Does anybody have any solid guides on how to go about managing users correctly using migrations with 2.1?
Note: If I change my connection string to be my sa user, it works fine. So the migration will go through. I'm just not wanting to give either full privileges to my site user or swapping credentials around in connection strings every time I need to run a migration.
I recently updated my schema in Symphony 2.7 project with Doctrine, but I was still getting an error. It turned out that I had to run:
app/console redis:flushall
In order for the schema to update accordingly and not be mapped incorrectly.
Is there a way for me to implement schema changes without having to kill user sessions when I run redis:flushall?
It's very inconvenient when deploying code to a production server to have to kill user sessions.
Thanks for your help!
I have some beginners questions regarding Symfony 2 which I cannot get clear answers for from previous questions (perhaps because they are genuinely basic)
When you create a new symfony2 project from the command line and specific the database name and passwords, is this meant to automatically create the database (which you can see in phpmyadmin) or does one manually do this.
Following from this, if one creates a number of entities and then uses
doctrine:schema:update
Should the specified tables be automatically created in the database you have specified in the projects "parameters.yml" file.
I have performed "doctrine:schema:update --force" which then gave me
Updating database schema...
Database schema updated successfully! "2" queries were executed
But no tables were created. So I tried again, to see what the message would be...
unknown-ec:35:86:4d:41:5e:symfony simonalice$ php app/console doctrine:schema:update --force
Nothing to update - your database is already in sync with the current entity metadata.
unknown-ec:35:86:4d:41:5e:symfony simonalice$
So clearly Doctrine thinks its in synch - but no tables in phpmyadmin.
Clearly complete beginners stuff....but I would be grateful for some steerage on this from a Symfony 2 veteran.
To answer your questions:
No, creating a new Symfony project will not create your database (or the user connecting to it). You still need to do that and I would recommend you create a dedicated user for your application with suitable permissions. You'll need to use a database user with administrative privileges to do this. For security reasons, it's best to not use your database administrator account with your application. To instruct doctrine to create your database (once you have your db user and connection parameters set), you can run the php app/console doctrine:database:create console command.
Yes, running the doctrine:schema:update console command will generate your database entities, but it won't/can't create your database. You can also use the --force option to apply changes you've made since the last update. These updates will still be bound by any column constraints you've defined, so if for example you change an existing nullable column to not null, you'll get an error if records already exist with null values.
Hope that helps.
I'm using Symfony2 version 2.0.5 with the bundled Doctrine ORM solution. Since I changed the environment from dev to prod, all my form inputs are escaped, when persisting to database. Now I know this is the correct behaviour for preventing sql injections, but when fetching the data back, the string isn't unescaped. Because I directly save JSON strings to database this is causing me big problems.
Also everytime I update this data the string gets escaped again and again.
My Question is, can I deactivate the escaping for certain fields, should I? Or can I unescape the values when fetched from the DB.
And why is this only happening in prod environment? Is this intended?
Best Regards, David!
This is probably caused by PHP configuration — not by Symfony or Doctrine. In php.ini, find all options starting with magic_quotes_ and set them to Off. Don't forget to restart the server.