mysql> create database videodnevnik CHARACTER SET utf8 collate
utf8_swedish_ci;
Query OK, 1 row affected (0.00 sec)
now my script runs as expected.
On 8 нояб, 01:26, "Anton Daneika" <mezh...@gmail.com> wrote:
> hello all,
>
> i need something like TEST_DATABASE_COLLATION, but in a normal django code
> -- not in the tests.
>
> i am running the same script in two environments: as a part of unit test and
> on it's own and get different results. i suspect the reason for getting
> different results is django's way of setting collations. my unit test fails
> when TEST_DATABASE_COLLATION option is set to utf8_unicode_ci, but runs ok
> if it's utf8_swedish_ci, however i do not know the way to set the collation
> for the application database. it seems strange that this option is only
> available for testing purposes. does anyone know how do i set different
> collation?
>
> the rest of this letter is for the curious ones.
> here's the example of the unit test script:
>
> class UnknownErrorTestCase(TestCase):
> fixtures = ['collation_error_db_state.json']
> def testUnknownError(self):
> lang = Language.objects.get(pk='sv')
> movie = Movie.objects.get(pk=10)
> movie.keywords.create(word='m n', language=lang)
>
> this test passes if TEST_DATABASE_COLLATION is utf8_swedish_ci and fails if
> it's utf8_unicode_ci (throws _mysql_exceptions.IntegrityError). the Keyword
> model has uniqueness constraint: unique_together = (("word", "language"),).
> the fixture loads a Keyword object whose "word" property is "man". this
> happens because 'man' == 'm n' if utf8_unicode_ci collation is used, so