﻿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
30748	Abstract model class specifies foreign key – MySQL doesn't have it	Mike Robinson	nobody	"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;
}}}

"	Uncategorized	new	Uncategorized	2.2	Normal				Unreviewed	0	0	0	0	0	0
