1

I am using Symfony 3.0.9 with FosUserBundle to build my app. I recently did a composer update and now I cannot create users via UserManager or command line. The error is Integrity constraint violation: 1048 Column 'salt' cannot be null. This error occurs even when I explicitly call parent::__construct() in my constructor method as show below:

/**
 * constructor.
 */
public function __construct()
{
    parent::__construct();
}

And also fails if I called the setSalt method like $user->setSalt('87234hjjdwshjdsjkds')

All efforts to resolve this have failed so I started to pay close attention to my composer update command and this was some of the output:

Updating dependencies (including require-dev)

Removing twig/twig (v1.24.1)
Installing twig/twig (v1.28.2)
   Loading from cache

Removing symfony/polyfill-util (v1.2.0)
Installing symfony/polyfill-util (v1.3.0)
   Loading from cache
  
  ...

Removing symfony/polyfill-intl-icu (v1.2.0)
Installing symfony/polyfill-intl-icu (v1.3.0)
   Loading from cache

Removing psr/log (1.0.0)
Installing psr/log (1.0.2)
   Loading from cache

Removing doctrine/cache (v1.6.0)
Installing doctrine/cache (v1.6.1)
   Loading from cache

   ...

Removing doctrine/orm (v2.5.4)
Installing doctrine/orm (v2.5.5)
   Loading from cache


Removing sensiolabs/security-checker (v3.0.2)
Installing sensiolabs/security-checker (v4.0.0)
   Loading from cache

Removing nikic/php-parser (v2.1.0)
Installing nikic/php-parser (v2.1.1)
   Loading from cache

 ...

Removing doctrine/doctrine-migrations-bundle (1.1.1)
Installing doctrine/doctrine-migrations-bundle (v1.2.0)
   Loading from cache
   
   ...
   
Removing phpspec/phpspec (2.5.1)
Installing phpspec/phpspec (2.5.5)
   Loading from cache

Removing doctrine/data-fixtures (v1.2.1)
Installing doctrine/data-fixtures (v1.2.2)
   Loading from cache

Updating friendsofsymfony/user-bundle dev-master (147ca68 => 7261f7a)
   Checking out 7261f7aa143b4bfdb0b7ddc5df208067fa7be698

As you can see FOSUSERBUNDLE was updated.

Reverting the composer update, deleting my vendor directory and running composer install fixes it. This summed it down to the update. That was the problem.

If anyone knows how I can update and still have a working application I would be grateful for your comments and feedback.

mrbabson
  • 13
  • 4
  • Did you updated your schema? As far as I remember, previous update removed some FOSUser entity field, and maybe you tryed to insert data on field which does not exist anymore. – Bart Bartoman Dec 06 '16 at 10:08
  • Thanks @BartBartoman, I will run 'composer update' and try again. – mrbabson Dec 06 '16 at 10:49
  • Yes! That worked! After the composer update I updated the schema and it updated the user table. That was awesome. Thanks – mrbabson Dec 06 '16 at 11:42
  • You are welcome. As a quicktips, just take time to pull, update dependencies, and update schema each time you start working again on your project. – Bart Bartoman Dec 06 '16 at 12:31

2 Answers2

0

If you want update everything but user-bundle

With composer you may pass package name(s) as parameter to composer update command, like this:

composer update vendor1/package1 vendor2/package2

So you can create long string of all packages except user-bundle. List of all oudated packages you can get from

composer show -o --name-only

command output.

The option -o here is for only outdated packages which are available for update.

Option --name-only obviously shows only package name without version and description.

So, on unix-like OS you can run something like

composer show -o --name-only | grep -v 'friendsofsymfony/user-bundle' | xargs composer update

More about Composer CLI

Nikita U.
  • 3,540
  • 1
  • 28
  • 37
  • Thanks Nikita. This is quite handy as at least I have the option of keep everything else up to date. Any ideas on how I can confirm this bug more solidly and provide details to the developers? – mrbabson Dec 06 '16 at 09:16
  • Well, you update your bundle to next major version (v2.0.0-beta1 according to your composer output), so major means BC breaks. As described here - https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Changelog.md there was `[BC break] The salt field of the User class is now nullable`. If you have troubles with explicitly setting salt, please provide full code snippet which doesn't work. – Nikita U. Dec 06 '16 at 10:08
0

1) If you want to use FOSUserBundle in version 2 there is no final/stable version - so you always have to expect breaking changes in a dev/master branch.

2) Since a couple of days there is a 2.0.0 Beta version at least which I heavily recommend to use in your case: Check it here.

3) There were a couple of changes regarding the User Database Schema, e.g a couple of unused fields were removed. And there is a change regarding the salt field - so in your case - as far as I can see probably the missing thing is to update your database schame (if you're working with Doctrine call bin/console doctrine:schema:update --force).

For details see e.g. the release notes for 2.0.0 beta:

[BC break] The salt field of the User class is now nullable.

LBA
  • 3,859
  • 2
  • 21
  • 60