Opened 6 years ago
Last modified 6 years ago
#30748 closed Bug
Abstract model class specifies foreign key – MySQL doesn't have it — at Initial Version
| Reported by: | Mike Robinson | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | dev |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
The abstract class is:
class AbstractForumProfile(models.Model):
"""
Represents the profile associated with each forum user.
"""
user = models.OneToOneField(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='forum_profile',
verbose_name=_('User'))
# The user's avatar.
avatar = ExtendedImageField(
verbose_name=_('Avatar'), null=True, blank=True,
upload_to=machina_settings.PROFILE_AVATAR_UPLOAD_TO,
**machina_settings.DEFAULT_AVATAR_SETTINGS)
# The user's signature.
signature = MarkupTextField(
verbose_name=_('Signature'), blank=True, null=True,
validators=[validators.NullableMaxLengthValidator(
machina_settings.PROFILE_SIGNATURE_MAX_LENGTH)])
# The amount of posts the user has posted (only approved posts are considered here).
posts_count = models.PositiveIntegerField(verbose_name=_('Total posts'), blank=True, default=0)
The derived class is:
class ForumProfile(AbstractForumProfile):
auto_subscribe_topics = models.BooleanField(
verbose_name='Automatically subscribe to topics you create.',
default=False)
notify_subscribed_topics = models.BooleanField(
verbose_name='Receive an email notification on new replies to subscribed topics.',
default=False)
but the resulting MySQL syntax (which does not show ON DELETE CASCADE on the FOREIGN KEY constraint, is:
CREATE TABLE `forum_member_forumprofile` ( `id` int(11) NOT NULL AUTO_INCREMENT, `avatar` varchar(100) DEFAULT NULL, `signature` longtext, `posts_count` int(10) unsigned NOT NULL, `_signature_rendered` longtext, `user_id` int(11) NOT NULL, `auto_subscribe_topics` tinyint(1) NOT NULL DEFAULT '0', `notify_subscribed_topics` tinyint(1) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `user_id` (`user_id`), CONSTRAINT `forum_member_forumprofile_user_id_9d6b9b6b_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=53 DEFAULT CHARSET=latin1;
Note:
See TracTickets
for help on using tickets.