﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31286	Database specific fields checks should be databases aware.	Hongtao Ma	Hongtao Ma	"In an attempt to trigger the check Error mentioned in Tickets: #31144, I found that the check for database backend doesn't check against the backend specified, e.g. --database mysql, rather, it always checks against the 'default' backend.

After diving into the source code, I found the following method defined in django/db/models/fields/__init__.py
{{{
    def _check_backend_specific_checks(self, **kwargs):
        app_label = self.model._meta.app_label
        for db in connections:
            if router.allow_migrate(db, app_label, model_name=self.model._meta.model_name):
                return connections[db].validation.check_field(self, **kwargs)
        return []
}}}
It checks the first db defined in connections rather those provided by users.

A proposed change would be:
{{{
    def _check_backend_specific_checks(self, **kwargs):
        app_label = self.model._meta.app_label
        errors = []
        for db in kwargs['databases'] or ['default']:
            if router.allow_migrate(db, app_label, model_name=self.model._meta.model_name):
                errors.extend(connections[db].validation.check_field(self, **kwargs))
        return errors
}}}

It worked as intended on my local machine.
I would happily provide a patch for this one."	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed		Simon Charette Jacob Walls	Ready for checkin	1	0	1	0	1	0
